package com.joysuch.wwyt.risk.service.impl;

import cn.hutool.core.date.DateUtil;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.joysuch.wwyt.bp.entity.BpDepart;
import com.joysuch.wwyt.bp.entity.BpJob;
import com.joysuch.wwyt.bp.repository.BpDepartDao;
import com.joysuch.wwyt.bp.repository.BpJobDao;
import com.joysuch.wwyt.common.constant.Constant;
import com.joysuch.wwyt.core.bean.BaseTypeGroupItemBean;
import com.joysuch.wwyt.core.bean.SimpleSelectListBean;
import com.joysuch.wwyt.core.common.util.DateTimeUtil;
import com.joysuch.wwyt.core.common.util.SimpleDateFormatCache;
import com.joysuch.wwyt.core.entity.BaseTypeGroup;
import com.joysuch.wwyt.core.entity.BaseTypeGroupItem;
import com.joysuch.wwyt.core.entity.BaseUser;
import com.joysuch.wwyt.core.enums.BaseConfigCodes;
import com.joysuch.wwyt.core.repository.BaseTypeGroupDao;
import com.joysuch.wwyt.core.repository.BaseTypeGroupItemDao;
import com.joysuch.wwyt.core.repository.BaseUserDao;
import com.joysuch.wwyt.core.service.BaseRoleDataAuthService;
import com.joysuch.wwyt.core.service.BaseTypeGroupItemService;
import com.joysuch.wwyt.core.service.BizCodeGeneratorFacade;
import com.joysuch.wwyt.core.support.Context;
import com.joysuch.wwyt.risk.bean.*;
import com.joysuch.wwyt.risk.entity.*;
import com.joysuch.wwyt.risk.entity.vo.RiskMeasureTypeNode;
import com.joysuch.wwyt.risk.enums.RiskPointStatus;
import com.joysuch.wwyt.risk.enums.SignInMethodEnum;
import com.joysuch.wwyt.risk.mapper.RiskMeasureTypeMapper;
import com.joysuch.wwyt.risk.repository.*;
import com.joysuch.wwyt.risk.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

@Service
@Slf4j
public class RiskEvaluationExcelImportServiceImpl implements RiskEvaluationExcelImportService {

    @Autowired
    private RiskEvaluationAnalyzeWayDao analyzeWayDao;
    @Autowired
    private RiskEvaluationAnalyzeMethodDao analyzeMethodDao;
    @Autowired
    private RiskEvaluationTargetTypeDao targetTypeDao;
    @Autowired
    private RiskEvaluationTargetItemDao targetItemDao;
    @Autowired
    private BaseTypeGroupItemDao baseTypeGroupItemDao;
    @Autowired
    private BaseTypeGroupDao baseTypeGroupDao;
    @Autowired
    private RiskPointDao riskPointDao;
    @Autowired
    private RiskPointTypeDao riskPointTypeDao;
    @Autowired
    private BaseUserDao baseUserDao;
    @Autowired
    private BpDepartDao bpDepartDao;
    @Autowired
    private RiskEvaluationBusinessService evaluationBusinessService;
    @Autowired
    private RiskDistrictDao riskDistrictDao;
    @Autowired
    private RiskPointService riskPointService;
    @Autowired
    private BaseRoleDataAuthService dataAuthService;
    @Autowired
    private RiskControlLevelService riskControllevelService;
    @Autowired
    private RiskMeasureTypeService riskMeasureTypeService;
    @Autowired
    private BpJobDao bpJobDao;
    @Autowired
    private RiskEvaluationControlDao riskEvaluationControlDao;
    @Autowired
    private RiskMeasureTypeMapper riskMeasureTypeMapper;
    @Autowired
    private BaseTypeGroupItemService baseTypeGroupItemService;
    @Autowired
    private BizCodeGeneratorFacade bizCodeGeneratorFacade;

    /**
     * 区域风险点/风险点库导入
     *
     * @param file
     * @return
     * @shared null/0 风险点  1风险点库
     */
    @Override
    public List<String> importDistrictEvaluationExcel(MultipartFile file, Integer shared) {
        XSSFWorkbook workbook = null;
        if (!file.getOriginalFilename().endsWith(".xlsx")) {
            throw new IllegalArgumentException("请使用xlsx文件导入");
        }
        RiskEvalMessageBean messageBean = new RiskEvalMessageBean(new ArrayList<>(), false);
        try {
            //判断文件大小
            if (!checkFileSize(file.getSize(), 5, "M")) {
                return Lists.newArrayList("文件大小不能超过5MB,请将数据拆分后上传");
            }
            workbook = new XSSFWorkbook(file.getInputStream());
            RiskEvaluationExcelMapBean mapBean = getExcelMapBean(shared);
            RiskEvaluationControl control = riskEvaluationControlDao.findByName("风险评估导入模板");
            RiskEvaluationControl storePointCtor = riskEvaluationControlDao.findByName("风险点库导入模板");
            //默认全国版
            Integer measureTypeFlag = 1;
            //默认横版
            Integer storePointFlag = 0;
            if (control == null) {
                measureTypeFlag = 1;
            } else {
                measureTypeFlag = control.getSwitchState();
            }
            if (storePointCtor == null) {
                storePointFlag = 0;
            } else {
                storePointFlag = storePointCtor.getSwitchState();
            }
            List<RiskEvaluationAnalyzeWay> pointAnalyzeWayList = analyzeWayDao.getPointAnalyzeWayList(0);
            if (CollectionUtils.isEmpty(mapBean.getTopTypes())) {
                return Lists.newArrayList("请先配置管控措施类型");
            }
            if (CollectionUtils.isEmpty(mapBean.getMethodMap()) || CollectionUtils.isEmpty(pointAnalyzeWayList)) {
                log.error("请先完善评估配置");
                return Lists.newArrayList("请先完善评估配置");
            }

            if (workbook != null) {
                for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
                    for (RiskEvaluationAnalyzeWay bean : pointAnalyzeWayList) {
                        if (bean.getName().equals(workbook.getSheetAt(i).getSheetName())) {
                            messageBean = getSheetData(workbook.getSheetAt(i), shared, messageBean, mapBean, measureTypeFlag, storePointFlag);
                        }
                    }
                }
            }
            if (!messageBean.getDataFlag()) {
                return Lists.newArrayList("导入文件为空或数据黏贴格式不正确，请检查内容或按照数值格式黏贴数据");
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Lists.newArrayList("导入失败");
        }
        return messageBean.getErrorMessages();
    }

    /**
     * 文件大小
     *
     * @param len  文件大小
     * @param size 限制大小
     * @param unit 单位
     * @return
     */
    public static boolean checkFileSize(Long len, int size, String unit) {
        double fileSize = 0;
        if ("B".equals(unit.toUpperCase())) {
            fileSize = (double) len;
        } else if ("K".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1024;
        } else if ("M".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1048576;
        } else if ("G".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1073741824;
        }
        if (fileSize > size) {
            return false;
        }
        return true;
    }

    private RiskEvaluationExcelMapBean getExcelMapBean(Integer shared) {
        RiskEvaluationExcelMapBean mapBean = new RiskEvaluationExcelMapBean();
        Map<String, List<RiskPointType>> pointTypeMap = new HashMap<>();
        List<RiskPointType> pointTypeList = riskPointTypeDao.findAll();
        if (!CollectionUtils.isEmpty(pointTypeList)) {
            pointTypeMap = pointTypeList.stream().collect(Collectors.groupingBy(RiskPointType::getName));
        }
        Map<String, List<RiskDistrict>> districtMap = new HashMap<>();
        List<RiskDistrict> districtList = riskDistrictDao.findAll();
        if (!CollectionUtils.isEmpty(districtList)) {
            districtMap = districtList.stream().collect(Collectors.groupingBy(RiskDistrict::getName));
        }

        Map<String, BpDepart> departMap = new HashMap<>();
        List<BpDepart> departList = bpDepartDao.findAll();
        List<String> dupDepartNames = bpDepartDao.getDuplicateDepartByName();
        if (!CollectionUtils.isEmpty(departList)) {
            for (BpDepart depart : departList) {
                departMap.put(depart.getName(), depart);
            }
        }
        Map<String, BaseUser> userMap = new HashMap<>();
        Map<String, BaseUser> userNameMap = new HashMap<>();
        Map<Long, List<BaseUser>> jobUserMap = new HashMap<>();
        List<BaseUser> userList = baseUserDao.findAll();

        if (!CollectionUtils.isEmpty(userList)) {
            for (BaseUser baseUser : userList) {
                userMap.put(baseUser.getCode(), baseUser);
                userNameMap.put(baseUser.getRealName(), baseUser);
            }
            jobUserMap = userList.stream().collect(Collectors.groupingBy(BaseUser::getJob));
        }
        List<String> duplicateNames = baseUserDao.getDuplicateUser();
        Map<Long, List<RiskEvaluationAnalyzeMethod>> methodMap = new HashMap<>();
        List<RiskEvaluationAnalyzeMethod> methodList = analyzeMethodDao.findAll();
        if (!CollectionUtils.isEmpty(methodList)) {
            methodMap = methodList.stream().collect(Collectors.groupingBy(RiskEvaluationAnalyzeMethod::getWayId));
        }

        Map<Long, List<Long>> evalTargetMap = new HashMap<>();
        List<RiskEvaluationAnalyzeMethod> methods = analyzeMethodDao.findAll();
        if (!CollectionUtils.isEmpty(methodList)) {
            for (RiskEvaluationAnalyzeMethod method : methods) {
                List<Long> typeIdList = targetTypeDao.getIdsByMethodId(method.getId());
                evalTargetMap.put(method.getId(), typeIdList);
            }
        }

        // 管控措施类型列表
        Map<String, RiskMeasureType> measureTypesMap = new HashMap<>();
        List<RiskMeasureType> measureLevelTypes = riskMeasureTypeMapper.getAll(Context.getCompanyCode(), Context.getCurrentTenantId());
        if (!CollectionUtils.isEmpty(measureLevelTypes)) {
            for (RiskMeasureType type : measureLevelTypes) {
                measureTypesMap.put(type.getTypeLevel() + "_" + type.getParentId() + "_" + type.getMeasureTypeName(), type);
            }
        }

        List<RiskMeasureTypeNode> measureTypes = riskMeasureTypeService.getAllChilds(null);
        mapBean.setAllMeasureTypes(measureTypes);
        mapBean.setMaxTypeLevel(3);
        //获取所有顶级措施
        List<RiskMeasureType> topTypes = riskMeasureTypeService.getTopTypes();
        List<BaseTypeGroupItem> controlTypeGroupItemList = new ArrayList<>();
        Map<Long, BaseTypeGroupItem> controlTypeGroupItemMap = new HashMap<>();
        Map<String, BaseTypeGroupItem> controlTypeGroupItemNameMap = new HashMap<>();
        Map<String, Long> troubleshootingMap = new HashMap<>();
        if (shared != null && shared == 1) {
            BaseTypeGroup controlType = baseTypeGroupDao.findByName("管控措施");
            if (controlType != null) {
                controlTypeGroupItemList = baseTypeGroupItemDao.findByTypeGroupId(controlType.getId());
                if (!CollectionUtils.isEmpty(controlTypeGroupItemList)) {
                    controlTypeGroupItemMap = controlTypeGroupItemList.stream().collect(Collectors.toMap(r -> r.getId(), r -> r));
                    controlTypeGroupItemNameMap = controlTypeGroupItemList.stream().collect(Collectors.toMap(r -> r.getName(), r -> r));
                }
            }
        } else {
            BaseTypeGroup controlType = baseTypeGroupDao.findByName("排查类型");
            if (controlType != null) {
                List<BaseTypeGroupItem> itemList = baseTypeGroupItemDao.findByTypeGroupId(controlType.getId());
                troubleshootingMap = itemList.stream().collect(Collectors.toMap(r -> r.getName(), r -> r.getId()));
            }
        }
        //管控层级
        List<SimpleSelectListBean> controllLevels = riskControllevelService.getAllForSimpleSelect();
        Map<String, Long> controlLevelMap = controllLevels.stream().collect(Collectors.toMap(SimpleSelectListBean::getLabel, SimpleSelectListBean::getValue));

        Map<String, Long> jobNameMap = new HashMap<>();
        Map<Long, String> jobIdMap = new HashMap<>();
        List<BpJob> jobList = bpJobDao.findAll();
        if (!CollectionUtils.isEmpty(jobList)) {
            jobNameMap = jobList.stream().collect(Collectors.toMap(BpJob::getName, BpJob::getId));
            jobIdMap = jobList.stream().collect(Collectors.toMap(BpJob::getId, BpJob::getName));
        }

        Map<String, Long> accessSourceMap = new HashMap<>();
        BaseTypeGroup accessSourceGroup = baseTypeGroupDao.findByName("取数来源");
        Long accessSourceGroupId = null;
        if (accessSourceGroup != null) {
            accessSourceGroupId = accessSourceGroup.getId();
            List<BaseTypeGroupItem> groupItemList = baseTypeGroupItemDao.findByTypeGroupId(accessSourceGroup.getId());
            if (!CollectionUtils.isEmpty(groupItemList)) {
                accessSourceMap = groupItemList.stream().collect(Collectors.toMap(BaseTypeGroupItem::getName, BaseTypeGroupItem::getId));
            }
        }
        Map<String, RiskPoint> districtIdPointNameMap = new HashMap<>();
        Map<String, RiskPoint> pointCodeMap = new HashMap<>();
        List<RiskPoint> pointList = riskPointDao.findAll();
        if (!CollectionUtils.isEmpty(pointList)) {
            for (RiskPoint point : pointList) {
                Long id = null;
                if (point.getRiskDistrict() != null) {
                    id = point.getRiskDistrict().getId();
                }
                districtIdPointNameMap.put(id + "_" + point.getShared() + "_" + point.getName(), point);
                pointCodeMap.put(point.getCode(), point);
            }
        }
        mapBean.setDepartMap(departMap);
        mapBean.setDistrictMap(districtMap);
        mapBean.setPointTypeMap(pointTypeMap);
        mapBean.setUserMap(userMap);
        mapBean.setMethodMap(methodMap);
        mapBean.setEvalTargetMap(evalTargetMap);
        mapBean.setControlLevelMap(controlLevelMap);
        mapBean.setJobNameMap(jobNameMap);
        mapBean.setJobIdMap(jobIdMap);
        mapBean.setJobUserMap(jobUserMap);
        mapBean.setUserNameMap(userNameMap);
        mapBean.setDuplicateNames(duplicateNames);
        mapBean.setDupDepartNames(dupDepartNames);
        mapBean.setMeasureTypesMap(measureTypesMap);
        mapBean.setAccessSourceGroupId(accessSourceGroupId);
        mapBean.setAccessSourceMap(accessSourceMap);
        mapBean.setDistrictIdPointNameMap(districtIdPointNameMap);
        mapBean.setPointCodeMap(pointCodeMap);
        mapBean.setTopTypes(topTypes);
        mapBean.setControlTypeGroupItemList(controlTypeGroupItemList);
        mapBean.setControlTypeGroupItemMap(controlTypeGroupItemMap);
        mapBean.setControlTypeGroupItemNameMap(controlTypeGroupItemNameMap);
        mapBean.setTroubleshootingMap(troubleshootingMap);
        return mapBean;
    }

    /**
     * 读取sheet数据
     *
     * @param sheet
     */
    private RiskEvalMessageBean getSheetData(XSSFSheet sheet, Integer shared, RiskEvalMessageBean messageBean, RiskEvaluationExcelMapBean mapBean, Integer measureTypeFlag, Integer storePointFlag) {
        List<String> errorMessages = messageBean.getErrorMessages();
        for (int i = 1; i < 4; i++) {
            XSSFRow row = sheet.getRow(i);
            if (row != null) {
                for (int j = 0; j < 3; j++) {
                    if (row.getCell(j) != null && getCellStringValue(row.getCell(j)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(j)))) {
                        messageBean.setDataFlag(true);
                    }
                }
            }
        }
        if (!messageBean.getDataFlag()) {
            return messageBean;
        }
        String sheetName = sheet.getSheetName();
        //确定 风险点编号0/评估时间?/项目5 所在的列
        RiskEvaluationAnalyzeWay analyzeWay = analyzeWayDao.findByNameAndAnalyzeType(sheetName, 0);
        RiskEvaluationAnalyzeWay evalyationWay = null;
        List<RiskEvaluationAnalyzeMethod> analyzeMethodList = new ArrayList<>();
        List<RiskEvaluationAnalyzeMethod> evaluationMethodList = new ArrayList<>();
        int pointCodeIndex = 0;
        //风险点全国版导入模板无风险点编号
        Integer pointNameIndex = null;
        int districtNameIndex = 0;
        int itemIndex = 3;  //作业分析库：第一部分固定项目 4个
        //风险点评估列索引列表 ： 第一部分固定项目 6个（风险点编号...,序号） + 分析方法配置项 + 评估方法配置项 + 管控措施类型级别数 + 管控措施内容+ 排查内容+ 评估人2个（工号，评估人）+评估时间 +责任人2个（工号，人）+ 责任单位2个（单位编号，名称）+管控层级
        int analyzeMethodCnt = 0;  //分析方法配置项个数
        int evalMethodCnt = 0; //评估方法配置项个数
        int measureTypeLevel = 1;
        if (shared == null || shared == 0) {
            measureTypeLevel = 3;
            pointCodeIndex = 1;
            itemIndex = 5;
            if (measureTypeFlag == 0) {
                pointCodeIndex = 0;
                districtNameIndex = 3;
                itemIndex = 4;
            }
        } else {
            //作业分析库措施类型只有一级
            mapBean.setMaxTypeLevel(1);
        }
        int evaluationTimeIndex = 0;
        if (analyzeWay == null) {
            throw new IllegalArgumentException("请先配置该分析方法");
        } else {
            evalyationWay = analyzeWayDao.findById(analyzeWay.getEvaluationId()).orElseThrow(() -> new IllegalArgumentException("评估方法有误"));
            //获取分析方法配置项个数
            analyzeMethodList = mapBean.getMethodMap().get(analyzeWay.getId());
            if (CollectionUtils.isEmpty(analyzeMethodList)) {
                throw new IllegalArgumentException("请完善评估方法[" + evalyationWay.getName() + "]配置项");
            }
            analyzeMethodList = analyzeMethodList.stream()
                    .sorted(Comparator.comparing(RiskEvaluationAnalyzeMethod::getOrderNumber, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
            analyzeMethodCnt = analyzeMethodList.size();  //分析方法配置项
            Long evaluationId = analyzeWay.getEvaluationId();
            if (evaluationId == null) {
                throw new IllegalArgumentException("请先配置该评估方法");
            }
            //获取评估方法配置项个数
            evaluationMethodList = mapBean.getMethodMap().get(evaluationId);
            if (CollectionUtils.isEmpty(evaluationMethodList)) {
                throw new IllegalArgumentException("请完善评估方法[" + evalyationWay.getName() + "]绑定方法的配置项");
            }
            evaluationMethodList = evaluationMethodList.stream()
                    .sorted(Comparator.comparing(RiskEvaluationAnalyzeMethod::getOrderNumber, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
            evalMethodCnt = evaluationMethodList.size();
        }
        //风险点固有评估开关
        boolean stablePointContrFlag = false;
        RiskEvaluationControl stablePointContr = riskEvaluationControlDao.findByName(BaseConfigCodes.WWYT_RISK_NAME);
        if (stablePointContr != null && stablePointContr.getSwitchState().equals(1)) {
            stablePointContrFlag = true;
        }
        List<RiskMeasureType> topTypes = mapBean.getTopTypes();
        //分组
        //评估时间列索引
        if (shared == null || shared == 0) {
            if (stablePointContrFlag) {
                if (measureTypeFlag == 2) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + evalMethodCnt + topTypes.size() + 1 + 2;
                } else if (measureTypeFlag == 1) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + evalMethodCnt + measureTypeLevel + 12;
                } else if (measureTypeFlag == 0) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + topTypes.size() + evalMethodCnt + evalMethodCnt + 2 + 2;
                }
            } else {
                if (measureTypeFlag == 2) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + topTypes.size() + 1 + 2;
                } else if (measureTypeFlag == 1) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + measureTypeLevel + 12;
                } else if (measureTypeFlag == 0) {
                    evaluationTimeIndex = itemIndex + analyzeMethodCnt + topTypes.size() + evalMethodCnt + 2 + 2;
                }
            }
        } else {
            //作业分析库： 分析方法， 评估方法，管控措施类型（一级）	措施内容	评估人工号	评估人	评估时间
            if (storePointFlag == 1) {
                evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + 1 + 1 + 2 + 1;
            } else {
                List<BaseTypeGroupItem> controlTypeGroupItemList = mapBean.getControlTypeGroupItemList();
                if (CollectionUtils.isEmpty(controlTypeGroupItemList)) {
                    throw new IllegalArgumentException("请在数据字典中配置管控措施");
                }
                evaluationTimeIndex = itemIndex + analyzeMethodCnt + evalMethodCnt + controlTypeGroupItemList.size() + 2 + 1;
            }
        }
        if ((shared == null || shared.intValue() == 0) && measureTypeFlag == 1) {
            pointNameIndex = 3;
        } else {
            pointNameIndex = pointCodeIndex + 1;
        }
        RiskExcelErrorMessageBean bean = convertDataMap(sheet, districtNameIndex, pointNameIndex, itemIndex, evaluationTimeIndex, sheetName, shared, mapBean, errorMessages);
        Map<String, List<Map<Date, List<Map<Integer, List<Integer>>>>>> dataGroupMap = bean.getDataGroupMap();
        errorMessages = bean.getErrorMessages();
        List<RiskPointEvaluationBusinessBean> riskPointEvaluationBusinessList = new ArrayList<>();
        List<Long> deptIds = dataAuthService.findDepartIdsByCurUser();
        //解析
        // 风险点评估集合
        for (Map.Entry<String, List<Map<Date, List<Map<Integer, List<Integer>>>>>> entry1 : dataGroupMap.entrySet()) {
            //风险点信息
            RiskPoint riskPoint = new RiskPoint();
            riskPoint.setShared(shared);
            List<Map<Date, List<Map<Integer, List<Integer>>>>> map2List = entry1.getValue();
            //风险辨识评估集合
            if (!CollectionUtils.isEmpty(map2List)) {
                for (Map<Date, List<Map<Integer, List<Integer>>>> map2 : map2List) {
                    for (Map.Entry<Date, List<Map<Integer, List<Integer>>>> entry2 : map2.entrySet()) {
                        RiskPointEvaluationBusinessBean riskPointEvaluationBusinessBean = new RiskPointEvaluationBusinessBean();
                        riskPointEvaluationBusinessBean.setAnalyzeWayId(analyzeWay.getId());
                        riskPointEvaluationBusinessBean.setPointAnalyzeType(1);
                        //评估时间
                        Date evaluationTime = entry2.getKey();
                        riskPointEvaluationBusinessBean.setEvaluationDate(evaluationTime);
                        riskPoint.setAuditDateTime(DateTimeUtil.date2LocalDateTime(evaluationTime));
                        //项目集合
                        List<RiskPointEvaluationItemAddBean> itemList = new ArrayList<>();
                        List<Map<Integer, List<Integer>>> map3List = entry2.getValue();
                        Integer businessRiskLevel = null;
                        Integer stableBusinessRiskLevel = null;

                        if (!CollectionUtils.isEmpty(map3List)) {
                            for (Map<Integer, List<Integer>> map3 : map3List) {
                                //解析map3数据
                                RiskExcelMapDataBean map3Data;
                                if (shared == null || shared == 0) {
                                    if (measureTypeFlag == 0) {
                                        map3Data = batchShanDongRiskPointAssessmentImport(sheet, map3, errorMessages, riskPoint, evalyationWay, analyzeMethodList, evaluationMethodList,
                                                riskPointEvaluationBusinessBean, businessRiskLevel, stableBusinessRiskLevel, districtNameIndex, pointCodeIndex, itemIndex, evaluationTimeIndex, itemList, mapBean, deptIds, stablePointContrFlag);
                                    } else {
                                        map3Data = batchRiskPointAssessmentImport(sheet, map3, errorMessages, riskPoint, evalyationWay, analyzeMethodList, evaluationMethodList,
                                                riskPointEvaluationBusinessBean, businessRiskLevel, stableBusinessRiskLevel, districtNameIndex, pointNameIndex, itemIndex, evaluationTimeIndex, itemList, mapBean, deptIds, stablePointContrFlag);
                                    }
                                } else {
                                    if (storePointFlag == 1) {
                                        map3Data = batchRiskPointLibraryEvaluationImport(sheet, map3, errorMessages, riskPoint, evalyationWay, analyzeMethodList, evaluationMethodList,
                                                riskPointEvaluationBusinessBean, businessRiskLevel, stableBusinessRiskLevel, pointCodeIndex, itemIndex, evaluationTimeIndex, itemList, mapBean);
                                    } else {
                                        map3Data = batchStorePointLibraryEvaluationImport(sheet, map3, errorMessages, riskPoint, evalyationWay, analyzeMethodList, evaluationMethodList,
                                                riskPointEvaluationBusinessBean, businessRiskLevel, stableBusinessRiskLevel, pointCodeIndex, itemIndex, evaluationTimeIndex, itemList, mapBean);
                                    }
                                }
                                itemList = map3Data.getItemList();
                                businessRiskLevel = map3Data.getBusinessRiskLevel();
                                stableBusinessRiskLevel = map3Data.getStableBusinessRiskLevel();
                            }
                        }
                        String pointName = riskPoint.getName();
                        String pointCode = riskPoint.getCode();
                        String pointType = riskPoint.getType();
                        if (shared == null || shared == 0) {
                            riskPoint.setStatus(RiskPointStatus.AUDIT_SUCCESS.getIndex());
                            if (riskPoint.getRiskDistrict() == null) {
                                continue;
                            }
                        }
                        String key = "null_" + shared + "_" + riskPoint.getName();
                        if (riskPoint.getRiskDistrict() != null) {
                            key = riskPoint.getRiskDistrict().getId() + "_" + shared + "_" + riskPoint.getName();
                        }
                        try {
                            if (StringUtils.isNotBlank(pointCode)) {
                                if (mapBean.getPointCodeMap().get(pointCode) == null) {
                                    //codeMap为空且districtIdPointNameMap为空->新增   codeMap为空且districtIdPointNameMap不为空->不增不改
                                    if (mapBean.getDistrictIdPointNameMap().get(key) == null) {
                                        riskPoint = addPoint(riskPoint, mapBean);
                                    } else {
                                        riskPoint = mapBean.getDistrictIdPointNameMap().get(key);
                                    }
                                } else {
                                    // codeMap不为空->修改
                                    riskPoint = mapBean.getPointCodeMap().get(riskPoint.getCode());
                                    riskPoint = updatePoint(riskPoint, shared, pointName, pointType, mapBean);
                                }
                            } else {
                                if (mapBean.getDistrictIdPointNameMap().get(key) == null) {
                                    //未填写风险编码且districtIdPointNameMap为空->新增
                                    riskPoint = addPoint(riskPoint, mapBean);
                                } else {
                                    //未填写风险编码且districtIdPointNameMap不为空->不增不改
                                    riskPoint = mapBean.getDistrictIdPointNameMap().get(key);
                                }
                            }
                            riskPointEvaluationBusinessBean.setItemList(itemList);
                            riskPointEvaluationBusinessBean.setRiskLevel(businessRiskLevel);
                            riskPointEvaluationBusinessBean.setStableRiskLevel(stableBusinessRiskLevel);
                            riskPointEvaluationBusinessBean.setPointId(riskPoint.getId());
                            riskPointEvaluationBusinessBean.setPointName(riskPoint.getName());
                            riskPointEvaluationBusinessBean.setShared(shared);
                        } catch (DataIntegrityViolationException e) {
                            errorMessages.add(sheetName + ":风险点," + riskPoint.getName() + "(" + riskPoint.getCode() + "),数据过长");
                            log.error(e.getMessage(), e);
                            continue;
                        } catch (IllegalArgumentException e) {
                            if (shared == null || shared == 0) {
                                errorMessages.add(sheetName + ": 风险区域(" + riskPoint.getRiskDistrict().getName() + "),风险点(" + riskPoint.getName() + ")数据异常[" + e.getMessage() + "]");
                            } else if (shared == 1) {
                                errorMessages.add(sheetName + ":风险点(" + riskPoint.getName() + ") 数据异常[" + e.getMessage() + "]");
                            }
                            log.error(e.getMessage(), e);
                            continue;
                        } catch (Exception e) {
                            errorMessages.add(sheetName + ":风险点," + riskPoint.getName() + "(" + riskPoint.getCode() + "),数据异常");
                            log.error(e.getMessage(), e);
                            continue;
                        }
                        //风险点控制评估
                        if (businessRiskLevel != null && !CollectionUtils.isEmpty(itemList)) {
                            riskPointEvaluationBusinessList.add(riskPointEvaluationBusinessBean);
                        }
                    }
                }
            }
        }
        //批量风险点控制评估
        if (!CollectionUtils.isEmpty(riskPointEvaluationBusinessList)) {
            try {
                evaluationBusinessService.batchSavePointEvaluation(riskPointEvaluationBusinessList, mapBean);
            } catch (Exception e) {
                errorMessages.add("导入失败,数据异常");
                log.error(e.getMessage(), e);
            }
        }
        messageBean.setErrorMessages(errorMessages);
        return messageBean;
    }

    private RiskExcelMapDataBean batchRiskPointAssessmentImport(XSSFSheet sheet, Map<Integer, List<Integer>> map3, List<String> errorMessages,
                                                                RiskPoint riskPoint, RiskEvaluationAnalyzeWay evalyationWay,
                                                                List<RiskEvaluationAnalyzeMethod> analyzeMethodList, List<RiskEvaluationAnalyzeMethod> evaluationMethodList,
                                                                RiskPointEvaluationBusinessBean riskPointEvaluationBusinessBean, Integer businessRiskLevel, Integer stableBusinessRiskLevel, Integer districtNameIndex,
                                                                Integer pointNameIndex, Integer itemIndex, Integer evaluationTimeIndex, List<RiskPointEvaluationItemAddBean> itemList,
                                                                RiskEvaluationExcelMapBean mapBean, List<Long> deptIds, boolean stablePointContrFlag) {
        Map<String, BpDepart> departMap = mapBean.getDepartMap();
        Map<String, List<RiskDistrict>> districtMap = mapBean.getDistrictMap();
        Map<String, List<RiskPointType>> pointTypeMap = mapBean.getPointTypeMap();
        Map<Long, List<Long>> evalTargetMap = mapBean.getEvalTargetMap();
        RiskExcelMapDataBean excelMapData = new RiskExcelMapDataBean();
        String sheetName = sheet.getSheetName();
        //隐患排查内容
        String hiddenDangerContent = null;
        XSSFRow row = null;
        Integer riskLevel = null;
        Integer stableRiskLevel = null;
        Map<Integer, List<RiskPointEvaluationDetailAddBean>> rowDataMap = new HashMap<>();
        Map<Integer, List<RiskPointStableDetailBean>> stableRowDataMap = new HashMap<>();
        List<Integer> validRowList = new ArrayList<>();

        //管控措施index
        int measureTypeIndex = 0;
        //固有评估
        int stableIndex = 0;
        //控制评估
        int controlIndex = 0;
        //隐患排查内容
        int dangerContentIndex = 0;
        //评估人index
        int evalUserIndex = evaluationTimeIndex + 1;
        //责任单位index
        int resDepartIndex = 0;
        //隐患问题描述index
        int dangersDescIndex = 0;
        //管控级别
        int controLevelIndex = 0;


        if (stablePointContrFlag) {
            measureTypeIndex = itemIndex + analyzeMethodList.size() + evaluationMethodList.size() + evaluationMethodList.size();
            stableIndex = itemIndex + analyzeMethodList.size();
            controlIndex = itemIndex + analyzeMethodList.size() + evaluationMethodList.size();
        } else {
            measureTypeIndex = itemIndex + analyzeMethodList.size() + evaluationMethodList.size();
            controlIndex = itemIndex + analyzeMethodList.size();
        }
        dangerContentIndex = evaluationTimeIndex - 10;
        resDepartIndex = evaluationTimeIndex + 2;
        controLevelIndex = evaluationTimeIndex + 3;
        dangersDescIndex = evaluationTimeIndex - 5;

        for (Map.Entry<Integer, List<Integer>> entry3 : map3.entrySet()) {
            RiskPointEvaluationItemAddBean itemAddBean = new RiskPointEvaluationItemAddBean();
            //风险点评估选项集合
            List<RiskPointEvaluationDetailAddBean> detailList = new ArrayList<>();
            List<RiskPointStableDetailBean> stableDetailList = new ArrayList<>();
            List<Integer> value = entry3.getValue();
            if (!CollectionUtils.isEmpty(value)) {
                int rowIndex = value.get(0);  //行索引
                validRowList.add(rowIndex);
                row = sheet.getRow(rowIndex);
//                if (row.getCell(pointCodeIndex) != null && getCellStringValue(row.getCell(pointCodeIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(pointCodeIndex)))) {
//                    String pointCode = getCellStringValue(row.getCell(pointCodeIndex));
//                    if (isNum(pointCode)) {
//                        pointCode = getNumberString(pointCode);
//                    }
//                    riskPoint.setCode(pointCode);
//                }

                //风险点名称
                if (row.getCell(pointNameIndex) == null || getCellStringValue(row.getCell(pointNameIndex)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointNameIndex)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险单元名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                //岗位
                int jobIndex=controLevelIndex-12;
                //排查人员
                int userIndex=controLevelIndex-11;
  /*              if (row.getCell(jobIndex) != null && getCellStringValue(row.getCell(jobIndex)) != null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }*/
//                BpJob bpJob;
//                if (row.getCell(jobIndex) != null && StringUtils.isNotBlank(row.getCell(jobIndex).toString())) {
//                    bpJob = bpJobDao.findByName(row.getCell(jobIndex).toString());
//                    if (bpJob == null) {
//                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位不存在");
//                        safeRemoveFromList(validRowList, rowIndex);
//                        continue;
//                    }
//                }
//                if (row.getCell(userIndex) != null && StringUtils.isNotBlank(row.getCell(userIndex).toString())) {
//                    String[] userNames = row.getCell(userIndex).toString().split(",");
//                    Integer noUser = 0;
//                    for (String userName : userNames) {
//                        Integer num = baseUserDao.findByUserName(userName);
//                        if (num <= 0) {
//                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查人员" + userName + "不存在");
//                            safeRemoveFromList(validRowList, rowIndex);
//                            noUser++;
//                        }
//                    }
//                    if (noUser > 0) {
//                        continue;
//                    }
//                }

                String pointName = getCellStringValue(row.getCell(pointNameIndex));
                if (isNum(pointName)) {
                    pointName = getNumberString(pointName);
                }
                riskPoint.setName(pointName);
                //风险点类型
                if (row.getCell(pointNameIndex + 1) == null || getCellStringValue(row.getCell(pointNameIndex + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointNameIndex + 1)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointTypeName = getCellStringValue(row.getCell(pointNameIndex + 1));
                if (StringUtils.isBlank(pointTypeName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                List<RiskPointType> typeList = null;
                if (pointTypeMap != null && pointTypeMap.size() > 0) {
                    typeList = pointTypeMap.get(pointTypeName);
                }
                if (CollectionUtils.isEmpty(typeList)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型 " + pointTypeName + " 不正确");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                riskPoint.setType(typeList.get(0).getCode());
                //风险区域名称
                if (row.getCell(districtNameIndex) == null || getCellStringValue(row.getCell(districtNameIndex)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(districtNameIndex)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String districtName = getCellStringValue(row.getCell(districtNameIndex)).trim();
                if (isNum(districtName)) {
                    districtName = getNumberString(districtName);
                }
                if (StringUtils.isBlank(districtName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                } else {
                    List<RiskDistrict> dsts = null;
                    if (districtMap != null && districtMap.size() > 0) {
                        dsts = districtMap.get(districtName);
                    }
                    if (CollectionUtils.isEmpty(dsts)) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称[" + districtName + "] 系统无此区域请先创建");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    } else {
                        if (!CollectionUtils.isEmpty(dsts)) {
                            List<Long> responsibleDepts = dsts.stream().map(RiskDistrict::getResponsibleDept).collect(toList());
                            List<Long> intersection = responsibleDepts.stream().filter(item -> deptIds.contains(Long.valueOf(item))).collect(toList());
                            if (CollectionUtils.isEmpty(intersection)) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,无权限导入该风险区域数据");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                        }
                        RiskDistrict d = riskDistrictDao.getByPointCode(riskPoint.getCode());
                        if (d != null && !d.getId().equals(dsts.get(0).getId())) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,该风险点已被其他风险区域关联");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                        riskPoint.setRiskDistrict(dsts.get(0));
                    }
                }
                Long responsibleDepart = null;
                List<Long> responsibleUsers = new ArrayList<>();
                //责任部门
                if (row.getCell(districtNameIndex + 1) != null && getCellStringValue(row.getCell(districtNameIndex + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(districtNameIndex + 1)))) {
                    String departStr = getCellStringValue(row.getCell(districtNameIndex + 1)).replace("，", ",");
                    if (StringUtils.isNotBlank(departStr)) {
                        if (isNum(departStr)) {
                            departStr = getNumberString(departStr);
                        }
                        if (mapBean.getDepartMap().get(departStr) != null) {
                            responsibleDepart = mapBean.getDepartMap().get(departStr).getId();
                        } else {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任部门填写错误");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                }

                //责任人
                if (row.getCell(districtNameIndex + 2) != null && getCellStringValue(row.getCell(districtNameIndex + 2)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(districtNameIndex + 2)))) {
                    String userStr = getCellStringValue(row.getCell(districtNameIndex + 2)).replace("，", ",");
                    if (StringUtils.isNotBlank(userStr)) {
                        boolean flag = true;
                        List<String> userNames = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(userStr);
                        for (String userName : userNames) {
                            if (isNum(userName)) {
                                userName = getNumberString(userName);
                            }
                            if (mapBean.getUserNameMap().get(userName) != null) {
                                BaseUser user = mapBean.getUserNameMap().get(userName);
                                if (!responsibleUsers.contains(user.getId())) {
                                    responsibleUsers.add(user.getId());
                                }
                            } else {
                                flag = false;
                            }
                        }
                        if (!flag) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任人填写错误");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                }
                riskPointEvaluationBusinessBean.setResponsibleDepart(responsibleDepart);
                riskPointEvaluationBusinessBean.setResponsibleUsers(responsibleUsers);
                if (row.getCell(evalUserIndex) != null && getCellStringValue(row.getCell(evalUserIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(evalUserIndex)))) {
                    String evaluationUserName = getCellStringValue(row.getCell(evalUserIndex)).replace("，", ",");
                    if (isNum(evaluationUserName)) {
                        evaluationUserName = getNumberString(evaluationUserName);
                    }
                    if (StringUtils.isBlank(evaluationUserName)) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人姓名不能为空");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    } else {
                        BaseUser evaluationUser = null;
                        List<String> nameStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(evaluationUserName);
                        List<Long> codeList = new ArrayList<>();
                        boolean isUserValid = true;
                        for (String name : nameStr) {
                            if (isNum(name)) {
                                name = getNumberString(name);
                            }
                            if (StringUtils.isNotBlank(name)) {
                                if (mapBean.getDuplicateNames().contains(name)) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人员姓名: " + name + ",有重名人员");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isUserValid = false;
                                    continue;
                                }
                                evaluationUser = mapBean.getUserNameMap().get(name);
                                if (evaluationUser == null) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人姓名" + name + "不存在");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isUserValid = false;
                                    continue;
                                } else {
                                    riskPoint.setAuditUserId(evaluationUser.getId());
                                }
                            }
                            codeList.add(evaluationUser.getId());
                        }
                        // 评估人有无效工号，则整条数据无效
                        if (!isUserValid) {
                            continue;
                        }
                        riskPointEvaluationBusinessBean.setEvaluationUserIds(codeList);

                    }
                }
                //分析方法
                for (int i = 0; i < analyzeMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = analyzeMethodList.get(i);
                    //判断是否必填
                    if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                        if (row.getCell(itemIndex + i + 1) == null || getCellStringValue(row.getCell(itemIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的分析方法不可为空");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                    if (row.getCell(itemIndex + i + 1) != null && getCellStringValue(row.getCell(itemIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(0);
                        //选项id
                        detailAddBean.setMethodId(method.getId());
                        if (method.getContentType() != null && method.getContentType() == 1) {
                            //选项
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            //0文本,1下拉选
                            detailAddBean.setContentType(1);
                            if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                List<RiskEvaluationTargetItem> targetItemList = targetItemDao.findByNameAndTypeIds(content, evalTargetMap.get(method.getId()));
                                if (!CollectionUtils.isEmpty(targetItemList)) {
                                    Long targetItemId = targetItemList.get(0).getId();
                                    detailAddBean.setTargetItemId(targetItemId);
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        } else {
                            //文本
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            if (isNum(content)) {
                                content = getNumberString(content);
                            }
                            detailAddBean.setContentType(0);
                            detailAddBean.setContent(content);
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }

                }

                //固有评估
                if (stablePointContrFlag) {
                    Double stableScore = null;
                    int stableEvalNum = 0;
                    for (int i = 0; i < evaluationMethodList.size(); i++) {
                        RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                        if (method.getContentType() != null && method.getContentType() == 0) {
                            if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                                if (row.getCell(stableIndex + i + 1) == null || getCellStringValue(row.getCell(stableIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(stableIndex + i + 1)))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的固有评估方法不可为空");
                                    continue;
                                }
                            }
                            if (row.getCell(stableIndex + i + 1) != null && getCellStringValue(row.getCell(stableIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(stableIndex + i + 1)))) {
                                RiskPointStableDetailBean detailAddBean = new RiskPointStableDetailBean();
                                //类型:0分析方法选项,1评估方法选项,2数据字典
                                detailAddBean.setMethodAnalyzeType(1);
                                //选项id
                                detailAddBean.setMethodId(method.getId());
                                //选项
                                String content = getCellStringValue(row.getCell(stableIndex + i + 1));
                                //0乘数,1乘积
                                detailAddBean.setContentType(0);
                                if (isNum(content)) {
                                    content = getNumberString(content);
                                    if (stableScore == null) {
                                        stableScore = Double.valueOf(content);
                                    } else {
                                        stableScore = stableScore * Double.valueOf(content);
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估方法只能填写数值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                                if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                    if (!CollectionUtils.isEmpty(items)) {
                                        detailAddBean.setTargetItemId(items.get(0).getId());
                                    } else {
                                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估方法未配置该分值");
                                        safeRemoveFromList(validRowList, rowIndex);
                                        continue;
                                    }
                                }

                                stableDetailList.add(detailAddBean);
                                stableRowDataMap.put(rowIndex, stableDetailList);
                                stableEvalNum++;
                            }
                        }
                    }
                    if (stableEvalNum < 1) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估选项至少填写一项");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }
                    if (stableScore == null) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的固有评估选项");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }

                    if (evalyationWay != null) {
                        if (stableScore < evalyationWay.getLowRisk() || stableScore.equals(evalyationWay.getLowRisk())) {
                            stableRiskLevel = 4;
                        } else if (stableScore > evalyationWay.getLowRisk() && (stableScore < evalyationWay.getGeneralRisk() || stableScore.equals(evalyationWay.getGeneralRisk()))) {
                            stableRiskLevel = 3;
                        } else if (stableScore > evalyationWay.getGeneralRisk() && (stableScore < evalyationWay.getHigherRisk() || stableScore.equals(evalyationWay.getHigherRisk()))) {
                            stableRiskLevel = 2;
                        } else if (stableScore > evalyationWay.getHigherRisk()) {
                            stableRiskLevel = 1;
                        }
                    }
                    if (stableBusinessRiskLevel == null) {
                        stableBusinessRiskLevel = stableRiskLevel;
                    } else {
                        if (stableBusinessRiskLevel > stableRiskLevel) {
                            stableBusinessRiskLevel = stableRiskLevel;
                        }
                    }
                    //乘积
                    for (int i = 0; i < evaluationMethodList.size(); i++) {
                        RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                        if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                            RiskPointStableDetailBean detailAddBean = new RiskPointStableDetailBean();
                            detailAddBean.setMethodAnalyzeType(1);
                            detailAddBean.setMethodId(method.getId());
                            detailAddBean.setContentType(1);
                            BigDecimal bg = new BigDecimal(stableScore);
                            double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            detailAddBean.setContent(doubleValue + "");
                            stableDetailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }
                }

                //控制评估方法
                Double score = null;
                int evalNum = 0;
                boolean evalFlag = true;
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType() == 0) {
                        if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                            if (row.getCell(controlIndex + i + 1) == null || getCellStringValue(row.getCell(controlIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(controlIndex + i + 1)))) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的评估方法不可为空");
                                continue;
                            }
                        }
                        if (row.getCell(controlIndex + i + 1) != null && getCellStringValue(row.getCell(controlIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(controlIndex + i + 1)))) {
                            RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                            //类型:0分析方法选项,1评估方法选项,2数据字典
                            detailAddBean.setMethodAnalyzeType(1);
                            //选项id
                            detailAddBean.setMethodId(method.getId());
                            //选项
                            String content = getCellStringValue(row.getCell(controlIndex + i + 1));
                            //0乘数,1乘积
                            detailAddBean.setContentType(0);
                            if (isNum(content)) {
                                content = getNumberString(content);
                                if (score == null) {
                                    score = Double.valueOf(content);
                                } else {
                                    score = score * Double.valueOf(content);
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法只能填写数值");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                            if (evalTargetMap != null) {
                                if (CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请完善配置项[" + method.getName() + "]中的配置");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    evalFlag = false;
                                    continue;
                                }
                                List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                if (!CollectionUtils.isEmpty(items)) {
                                    detailAddBean.setTargetItemId(items.get(0).getId());
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法未配置该分值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                            evalNum++;
                        }
                    }
                }
                if (evalNum < 1 && evalFlag) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估选项至少填写一项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                if (score == null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的评估选项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }

                if (evalyationWay != null) {
                    if (score < evalyationWay.getLowRisk() || score.equals(evalyationWay.getLowRisk())) {
                        riskLevel = 4;
                    } else if (score > evalyationWay.getLowRisk() && (score < evalyationWay.getGeneralRisk() || score.equals(evalyationWay.getGeneralRisk()))) {
                        riskLevel = 3;
                    } else if (score > evalyationWay.getGeneralRisk() && (score < evalyationWay.getHigherRisk() || score.equals(evalyationWay.getHigherRisk()))) {
                        riskLevel = 2;
                    } else if (score > evalyationWay.getHigherRisk()) {
                        riskLevel = 1;
                    }
                }
                if (businessRiskLevel == null) {
                    businessRiskLevel = riskLevel;
                } else {
                    if (businessRiskLevel > riskLevel) {
                        businessRiskLevel = riskLevel;
                    }
                }
                //乘积
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        detailAddBean.setMethodAnalyzeType(1);
                        detailAddBean.setMethodId(method.getId());
                        detailAddBean.setContentType(1);
                        BigDecimal bg = new BigDecimal(score);
                        double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        detailAddBean.setContent(doubleValue + "");
                        detailList.add(detailAddBean);
                        rowDataMap.put(rowIndex, detailList);
                    }
                }

                itemAddBean.setRiskLevel(riskLevel);
                itemAddBean.setStableRiskLevel(stableRiskLevel);
                //安全措施+风险分级管控
                boolean isDataValid = true;
                Map<String, List<Long>> validateUserMap = new HashMap<>();
                Map<String, List<Long>> validateJobMap = new HashMap<>();
                for (Integer inte : value) {
                    row = sheet.getRow(inte);
                    rowIndex = inte;
                    //风险分级管控
                    //责任人工号
                    List<Long> responseUserIds = new ArrayList<>();
                    //责任部门单位
                    List<Long> responseDepartIds = new ArrayList<>();
                    //管控层级
                    List<Long> controlLevelIds = new ArrayList<>();
                    //取数来源id
                    Long accessSourceId = null;
                    //排查类型id
                    Long troubleshootingTypeId = null;
                    //管控状态
                    Integer controlorState = null;
                    //排查人员 key:岗位id value 人员集合
                    Map<Long, List<BaseUser>> checkJobMap = new LinkedHashMap<>();
                    //排查频率
                    List<Integer> periodDaysList = new ArrayList<>();
                    //排查周
                    List<String> periodWeekList = new ArrayList<>();
                    //排查周期
                    String periodUnits = null;
                    //隐患问题描述
                    String hiddenDangersDesc = null;
                    //排查计划备注
                    String planRemark = null;
                    //排查周期开始时间
                    Date startTime = null;
                    //排查周期结束时间
                    Date endTime = null;
                    //排查类型
                    String troubleshootingType = null;
                    // 排查计划岗位集合
                    List<Long> investigateJobIds = new ArrayList<>();
                    int controlNum = 0;
                    if (row.getCell(resDepartIndex) != null && getCellStringValue(row.getCell(resDepartIndex)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(resDepartIndex)))) {
                        String responseDepartNames = getCellStringValue(row.getCell(resDepartIndex)).replace("，", ",");
                        List<String> namesStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(responseDepartNames).stream().distinct().collect(toList());
                        isDataValid = true;
                        if (namesStr.size() > 10) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请不要填写10个以上的责任单位");
                            safeRemoveFromList(validRowList, rowIndex);
                            isDataValid = false;
                            continue;
                        }
                        for (String name : namesStr) {
                            if (isNum(name)) {
                                name = getNumberString(name);
                            }
                            if (StringUtils.isNotBlank(name)) {
                                BpDepart responseDepart = null;
                                if (mapBean.getDupDepartNames().contains(name)) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任单位[" + name + "]名称已存在");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isDataValid = false;
                                    continue;
                                }
                                if (departMap != null && departMap.size() > 0) {
                                    responseDepart = departMap.get(name);
                                }
                                if (responseDepart != null) {
                                    if (!responseDepartIds.contains(responseDepart.getId())) {
                                        responseDepartIds.add(responseDepart.getId());
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任单位[" + name + "]不存在");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isDataValid = false;
                                    continue;
                                }
                            }
                        }
                        if (!isDataValid) {
                            continue;
                        }
                        if (responseDepartIds.size() > 0) {
                            controlNum++;
                        }
                    }

                    if (row.getCell(controLevelIndex) != null && getCellStringValue(row.getCell(controLevelIndex)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(controLevelIndex)))) {
                        String controlLevel = getCellStringValue(row.getCell(controLevelIndex)).replace("，", ",");
                        isDataValid = true;
                        if (StringUtils.isNotBlank(controlLevel)) {
                            // 管控层级多选
                            List<String> levels = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(controlLevel);
                            for (String level : levels) {
                                Long levelId = mapBean.getControlLevelMap().get(level.trim());
                                if (levelId != null) {
                                    if (!controlLevelIds.contains(levelId)) {
                                        controlLevelIds.add(levelId);
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控层级" + level + "不存在");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isDataValid = false;
                                    continue;
                                }
                            }
                        }

                        if (!isDataValid) {
                            continue;
                        }
                        if (controlLevelIds.size() > 0) {
                            controlNum++;
                        }
                    }
                    if (controlNum == 0) {
                        controlorState = 1;
                    } else if (controlNum == 2) {
                        controlorState = 2;
                    } else {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行,请正确填写责任单位编码,管控级别");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }

                    int checkPlanNum = 0;
                    //隐患描述
                    if (row.getCell(dangersDescIndex) != null && getCellStringValue(row.getCell(dangersDescIndex)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex)))) {
                        hiddenDangersDesc = getCellStringValue(row.getCell(dangersDescIndex));
                        if (isNum(hiddenDangersDesc)) {
                            hiddenDangersDesc = getNumberString(hiddenDangersDesc);
                        }
                    }

                    List<String> pers = new ArrayList<>();
                    //排查周期
                    if (row.getCell(dangersDescIndex - 2) != null && getCellStringValue(row.getCell(dangersDescIndex - 2)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex - 2)))) {
                        String periodDaysListStr = getCellStringValue(row.getCell(dangersDescIndex - 2)).replace("，", ",");
                        isDataValid = true;
                        if (StringUtils.isNotBlank(periodDaysListStr)) {
                            periodDaysListStr.trim();
                            pers = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(periodDaysListStr);
                        }
                        if (!isDataValid) {
                            continue;
                        }
                    }

                    //排查频率
                    if (row.getCell(dangersDescIndex - 1) != null && getCellStringValue(row.getCell(dangersDescIndex - 1)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex - 1)))) {
                        periodUnits = getCellStringValue(row.getCell(dangersDescIndex - 1)).replace("，", ",");
                        isDataValid = true;
                        if (StringUtils.isNotBlank(periodUnits)) {
                            if (!periodUnits.equals("时") && !periodUnits.equals("天") && !periodUnits.equals("月") && !periodUnits.equals("年")) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,周期单元" + periodUnits + "错误,请在" + "时 天 月 年" + "中选择");
                                periodUnits = null;
                                isDataValid = false;
                                continue;
                            }
                        }
                        for (String per : pers) {
                            if (periodUnits.equals("天")){
                                if (isNum(per)) {
                                    per = getNumberString(per);
                                    BigDecimal bigDecimal = new BigDecimal(per).setScale(0, BigDecimal.ROUND_HALF_UP);
                                    if (!periodDaysList.contains(bigDecimal.intValue())) {
                                        periodDaysList.add(bigDecimal.intValue());
                                    }
                                } else {
                                    //如果不是数字，进行周几判断
                                    if (isWeek(per)){
                                        periodWeekList.add(per);
                                        Integer day = getWeekNum(per);
                                        if (!periodDaysList.contains(day)) {
                                            periodDaysList.add(day);
                                        }
                                    }else {
                                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,周期" + per + "请填写数值类型或周一至周日");
                                        isDataValid = false;
                                        continue;
                                    }
                                }
                            }else {
                                if (isNum(per)) {
                                    per = getNumberString(per);
                                    BigDecimal bigDecimal = new BigDecimal(per).setScale(0, BigDecimal.ROUND_HALF_UP);
                                    if (!periodDaysList.contains(bigDecimal.intValue())) {
                                        periodDaysList.add(bigDecimal.intValue());
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,周期" + per + "请填写数值类型");
                                    isDataValid = false;
                                    continue;
                                }
                            }

                        }
//                        if (periodUnits.equals("周") && !CollectionUtils.isEmpty(periodDaysList)) {
//                            if (!periodDaysList.contains(1) && !periodDaysList.contains(2) && !periodDaysList.contains(3) && !periodDaysList.contains(4) &&
//                                    !periodDaysList.contains(5) && !periodDaysList.contains(6) && !periodDaysList.contains(7)) {
//                                errorMessages.add(sheetName + ":第" + (inte + 1) + "行,排查周期为周,排查频率请填写 0-7 的数字");
//                                safeRemoveFromList(validRowList, rowIndex);
//                                isDataValid = false;
//                                continue;
//                            }
//                        }
                        if (!isDataValid) {
                            continue;
                        }
                    }

                    //取数来源
                    if (row.getCell(dangersDescIndex + 1) != null && getCellStringValue(row.getCell(dangersDescIndex + 1)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex + 1)))) {
                        String sourceStr = getCellStringValue(row.getCell(dangersDescIndex + 1));
                        if (isNum(sourceStr)) {
                            sourceStr = getNumberString(sourceStr);
                        }
                        Map<String, Long> accessSourceMap = mapBean.getAccessSourceMap();
                        accessSourceId = accessSourceMap.get(sourceStr);
                        Long accessSourceGroupId = mapBean.getAccessSourceGroupId();
                        if (accessSourceId == null) {
                            if (accessSourceGroupId == null) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,数据字典类型 取数来源 不存在");
                                continue;
                            } else {
                                BaseTypeGroupItemBean bean = new BaseTypeGroupItemBean();
                                bean.setName(sourceStr);
                                bean.setTypeGroupId(accessSourceGroupId);
                                bean.setShowOrder(10);
                                BaseTypeGroupItem item = null;
                                try {
                                    item = baseTypeGroupItemService.addItem(bean);
                                } catch (Exception e) {
                                    log.error(e.getMessage(), e);
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行," + e.getMessage());
                                    continue;
                                }
                                if (item != null) {
                                    accessSourceId = item.getId();
                                    accessSourceMap.put(item.getName(), item.getId());
                                    mapBean.setAccessSourceMap(accessSourceMap);
                                }
                            }
                        }
                    }

                    //备注
                    if (row.getCell(dangersDescIndex + 2) != null && getCellStringValue(row.getCell(dangersDescIndex + 2)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex + 2)))) {
                        planRemark = getCellStringValue(row.getCell(dangersDescIndex + 2));
                        if (isNum(planRemark)) {
                            planRemark = getNumberString(planRemark);
                        }
                    }
                    //周期开始时间
                    if ("时".equals(periodUnits) && row.getCell(dangersDescIndex + 3) != null && getCellStringValue(row.getCell(dangersDescIndex + 3)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex + 3)))) {
                            String startTimeStr = getCellStringValue(row.getCell(dangersDescIndex + 3));
                            String hourStr = getHour(startTimeStr);
                            if (StringUtils.isNotBlank(hourStr) && Integer.parseInt(hourStr) >= 0 && Integer.parseInt(hourStr) <= 24){
                                startTime = DateUtil.offsetHour(DateUtil.beginOfDay(DateUtil.date()), Integer.parseInt(hourStr));
                            }else {
                                errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 周期开始时间,请填写 0点-24点");
                            continue;
                        }
                    }
                    //周期结束时间
                    if ("时".equals(periodUnits) && row.getCell(dangersDescIndex + 4) != null && getCellStringValue(row.getCell(dangersDescIndex + 4)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex + 4)))) {
                            String startEndStr = getCellStringValue(row.getCell(dangersDescIndex + 4));
                            String hourStr = getHour(startEndStr);
                            if (StringUtils.isNotBlank(hourStr) && Integer.parseInt(hourStr) >= 0 && Integer.parseInt(hourStr) <= 24){
                                if (Integer.parseInt(hourStr) != 24){
                                    endTime = DateUtil.offsetHour(DateUtil.beginOfDay(DateUtil.date()), Integer.parseInt(hourStr));
                                    if (startTime.after(endTime)){
                                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 周期开始时间应小于周期结束时间");
                                        continue;
                                    }
                                }
                            }else {
                                errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 周期结束时间,请填写 0点-24点");
                            continue;
                        }
                    }

                    //排查类型
                    if (row.getCell(evaluationTimeIndex + 4) != null && getCellStringValue(row.getCell(evaluationTimeIndex + 4)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(evaluationTimeIndex + 4)))) {
                        troubleshootingType = getCellStringValue(row.getCell(evaluationTimeIndex + 4));
                        Map<String, Long> troubleshootingMap = mapBean.getTroubleshootingMap();
                        if (troubleshootingMap.get(troubleshootingType) != null) {
                            troubleshootingTypeId = troubleshootingMap.get(troubleshootingType);
                        } else {
                            errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 排查类型不存在,请在数据字典中查看相应配置");
                            continue;
                        }
                    }

                    Map<String, RiskMeasureType> measureTypesMap = mapBean.getMeasureTypesMap();
                    String content = null;
                    if (checkNullCell(row, measureTypeIndex + 1)) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 管控措施类型不能为空");
                        continue;
                    }
                    String firstTypeName = getCellStringValue(row.getCell(measureTypeIndex + 1)).toString().trim();
                    if (isNum(firstTypeName)) {
                        firstTypeName = getNumberString(firstTypeName);
                    }
                    RiskMeasureType firstType = measureTypesMap.get("1_null_" + firstTypeName);
                    if (firstType == null) {
                        firstType = saveRiskMeasureType(firstTypeName, null, 1, measureTypesMap.size());
                        measureTypesMap.put("1_null_" + firstTypeName, firstType);
                        mapBean.setMeasureTypesMap(measureTypesMap);

                    }
                    //默认存放管控类型一级ID
                    mapBean.setMeasureTypeId(firstType.getId());
                    if (!checkMeasureType(mapBean, row, measureTypeIndex, inte, sheetName, firstType, errorMessages)) {
                        continue;
                    }
                    int measureContentIndex = measureTypeIndex + mapBean.getMaxTypeLevel();

                    if (checkNullCell(row, measureContentIndex + 1)) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行 管控措施内容不能为空");
                        continue;
                    }
                    content = getCellStringValue(row.getCell(measureContentIndex + 1)).trim();

                    if (isNum(content)) {
                        content = getNumberString(content);
                    }
                    if (content.length() > 2000) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行 管控措施内容不能超过2000个字");
                        continue;
                    }
                    //隐患排查内容
                    if (!checkNullCell(row, dangerContentIndex)) {
                        hiddenDangerContent = getCellStringValue(row.getCell(dangerContentIndex));
                        if (isNum(hiddenDangerContent)) {
                            hiddenDangerContent = getNumberString(hiddenDangerContent);
                        }
                        if (hiddenDangerContent.length() > 512) {
                            errorMessages.add(sheetName + ":第" + (inte + 1) + "行 隐患排查内容不能超过512个字");
                            continue;
                        }
                    } else {
                        hiddenDangerContent = null;
                    }
                    if (StringUtils.isBlank(hiddenDangerContent) && (!CollectionUtils.isEmpty(checkJobMap) || StringUtils.isNotBlank(periodUnits) ||
                            !CollectionUtils.isEmpty(periodDaysList) || !CollectionUtils.isEmpty(investigateJobIds) || StringUtils.isNotBlank(troubleshootingType))) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行,请填写隐患排查内容再设置排查人员 排查周期 排查频率 排查类型");
                        continue;
                    }

                    //校验 同一一排查内容下 同一人员和岗位不能存在俩个计划中
                    String validateKey = this.getValidateKey(mapBean.getMeasureTypeId(), content, hiddenDangerContent, periodUnits, periodDaysList);
                    boolean planflag = false;
                    List<Long> validateUserIds = validateUserMap.get(validateKey);
                    if (row.getCell(dangersDescIndex - 3) != null && getCellStringValue(row.getCell(dangersDescIndex - 3)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex - 3)))) {
                        String checkUserName = getCellStringValue(row.getCell(dangersDescIndex - 3)).replace("，", ",");

                        isDataValid = true;
                        if (StringUtils.isNotBlank(checkUserName)) {
                            planflag = true;
                            List<String> checkUserNameList = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(checkUserName);
                            for (String name : checkUserNameList) {
                                if (isNum(name)) {
                                    name = getNumberString(name);
                                }
                                if (mapBean.getDuplicateNames().contains(name)) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查人员姓名: " + name + ",有重名人员");
                                    isDataValid = false;
                                    continue;
                                } else {
                                    BaseUser user = mapBean.getUserNameMap().get(name);
                                    if (user != null) {
                                        if (CollectionUtils.isEmpty(validateUserIds)) {
                                            validateUserIds = new ArrayList<>();
                                            validateUserIds.add(user.getId());
                                        } else {
                                            if (validateUserIds.contains(user.getId())) {
                                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查人员" + name + "不能在同一隐患排查内容下重复");
                                                isDataValid = false;
                                                continue;
                                            } else {
                                                validateUserIds.add(user.getId());
                                            }
                                        }
                                        validateUserMap.put(validateKey, validateUserIds);
                                        Long job = user.getJob();
                                        List<BaseUser> users = checkJobMap.get(job);
                                        if (CollectionUtils.isEmpty(users)) {
                                            List<BaseUser> checkUserList = new ArrayList<>();
                                            checkUserList.add(user);
                                            checkJobMap.put(job, checkUserList);
                                        } else {
                                            if (!users.contains(user)) {
                                                users.add(user);
                                                checkJobMap.put(job, users);
                                            }
                                        }
                                    } else {
                                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,人员" + name + "不存在");
                                        isDataValid = false;
                                        continue;
                                    }
                                }
                            }
                        }
                        if (!isDataValid) {
                            continue;
                        }
                    }

                    List<Long> validateJobIds = validateJobMap.get(validateKey);
                    if (row.getCell(dangersDescIndex - 4) != null && getCellStringValue(row.getCell(dangersDescIndex - 4)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(dangersDescIndex - 4)))) {
                        String checkJobName = getCellStringValue(row.getCell(dangersDescIndex - 4)).replace("，", ",");
                        isDataValid = true;
                        if (StringUtils.isNotBlank(checkJobName)) {
                            List<String> checkJobNameList = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(checkJobName);
                            List<String> jobDistinctList = checkJobNameList.stream().distinct().collect(toList());
                            if (jobDistinctList.size() > 1) {
                                if (!planflag) {
                                    errorMessages.add(sheetName + ":第" + (inte + 1) + "行,暂不支持一个计划下填写多个岗位");
                        continue;
                    }
                            }
                            for (String name : checkJobNameList) {
                                if (isNum(name)) {
                                    name = getNumberString(name);
                                }
                                Long jobId = mapBean.getJobNameMap().get(name);
                                if (jobId != null) {
                                    if (CollectionUtils.isEmpty(validateJobIds)) {
                                        validateJobIds = new ArrayList<>();
                                        validateJobIds.add(jobId);
                                    } else {
                                        if (validateJobIds.contains(jobId)) {
                                            if (!planflag) {
                                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位" + name + "不能在同一隐患排查内容下重复");
                                                isDataValid = false;
                                                continue;
                                            }
                                        } else {
                                            validateJobIds.add(jobId);
                                        }
                                    }
                                    validateJobMap.put(validateKey, validateJobIds);
                                    if (!investigateJobIds.contains(jobId)) {
                                        investigateJobIds.add(jobId);
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位" + name + "不存在");
                                    isDataValid = false;
                                    continue;
                                }
                            }
                        }
                        if (!isDataValid) {
                            continue;
                        }
                    }
                    if (!CollectionUtils.isEmpty(investigateJobIds)) {
                        checkPlanNum++;
                    }
                    if (!CollectionUtils.isEmpty(checkJobMap)) {
                        checkPlanNum++;
                    }
                    if (!CollectionUtils.isEmpty(periodDaysList) || !CollectionUtils.isEmpty(periodWeekList)) {
                        checkPlanNum++;
                    }

                    if (StringUtils.isNotBlank(periodUnits)) {
                        checkPlanNum++;
                    }

                    if (controlNum != 2 && checkPlanNum > 0) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行,请填写责任单位和管控级别再设置排查人员 排查周期 排查频率");
                        continue;
                    }
                    if (checkPlanNum > 0 && checkPlanNum < 3) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行,请设置排查岗位/排查人员 排查周期 排查频率");
                        continue;
                    }

                    detailList = builderDetailAddBean(detailList, mapBean, content, controlLevelIds, responseUserIds, responseDepartIds, controlorState,
                            hiddenDangerContent, accessSourceId, troubleshootingTypeId, hiddenDangersDesc, planRemark, checkJobMap, periodUnits, periodDaysList,periodWeekList,startTime,endTime, investigateJobIds);
                    rowDataMap.put(inte, detailList);
                }
            }
            //根据数据校验结果，保存有效数据行内容
            if (validRowList.size() > 0) {
                for (Integer r : validRowList) {
                    itemAddBean.setDetailList(rowDataMap.get(r));
                    itemAddBean.setStableDetailList(stableRowDataMap.get(r));
                    itemList.add(itemAddBean);
                }
                validRowList.clear();
            }
        }
        excelMapData.setItemList(itemList);
        excelMapData.setBusinessRiskLevel(businessRiskLevel);
        excelMapData.setStableBusinessRiskLevel(stableBusinessRiskLevel);
        // 评估内容为空时， 风险点信息不做导入
        if (itemList != null && !itemList.isEmpty()) {
            excelMapData.setPointCode(riskPoint.getCode());
        }
        return excelMapData;
    }

    private String getValidateKey(Long measureTypeId, String content, String hiddenDangerContent, String periodUnits, List<Integer> periodDaysList) {
        return measureTypeId + "_" + content + "_" + hiddenDangerContent + "_" + periodUnits + "_" + (CollectionUtils.isEmpty(periodDaysList) ? "" : periodDaysList.stream().map(String::valueOf).collect(Collectors.joining(",")));
    }

    private RiskExcelMapDataBean batchShanDongRiskPointAssessmentImport(XSSFSheet sheet, Map<Integer, List<Integer>> map3, List<String> errorMessages,
                                                                        RiskPoint riskPoint, RiskEvaluationAnalyzeWay evalyationWay,
                                                                        List<RiskEvaluationAnalyzeMethod> analyzeMethodList, List<RiskEvaluationAnalyzeMethod> evaluationMethodList,
                                                                        RiskPointEvaluationBusinessBean riskPointEvaluationBusinessBean, Integer businessRiskLevel, Integer stableBusinessRiskLevel, Integer districtNameIndex,
                                                                        Integer pointCodeIndex, Integer itemIndex, Integer evaluationTimeIndex, List<RiskPointEvaluationItemAddBean> itemList,
                                                                        RiskEvaluationExcelMapBean mapBean, List<Long> deptIds, boolean stablePointContrFlag) {
        Map<String, BpDepart> departMap = mapBean.getDepartMap();
        Map<String, List<RiskDistrict>> districtMap = mapBean.getDistrictMap();
        Map<String, List<RiskPointType>> pointTypeMap = mapBean.getPointTypeMap();
        Map<Long, List<Long>> evalTargetMap = mapBean.getEvalTargetMap();
        RiskExcelMapDataBean excelMapData = new RiskExcelMapDataBean();
        String sheetName = sheet.getSheetName();
        //隐患排查内容
        String hiddenDangerContent = null;
        XSSFRow row = null;
        Integer riskLevel = null;
        Integer stableRiskLevel = null;
        Map<Integer, List<RiskPointEvaluationDetailAddBean>> rowDataMap = new HashMap<>();
        Map<Integer, List<RiskPointStableDetailBean>> stableRowDataMap = new HashMap<>();
        List<Integer> validRowList = new ArrayList<>();

        //管控措施index
        int measureTypeIndex = 0;
        //固有评估
        int stableIndex = 0;
        //控制评估
        int controlIndex = 0;
        //评估人index
        int evalUserIndex = evaluationTimeIndex - 1;
        //责任单位index
        int resDepartIndex = 0;
        //管控级别
        int controLevelIndex = evaluationTimeIndex - 1;

        evalUserIndex = evaluationTimeIndex - 2;
        measureTypeIndex = itemIndex + analyzeMethodList.size();
        if (stablePointContrFlag) {
            controlIndex = itemIndex + analyzeMethodList.size() + mapBean.getTopTypes().size() + evaluationMethodList.size();
            stableIndex = itemIndex + analyzeMethodList.size() + mapBean.getTopTypes().size();
        } else {
            controlIndex = itemIndex + analyzeMethodList.size() + mapBean.getTopTypes().size();
        }
        resDepartIndex = evaluationTimeIndex - 3;

        for (Map.Entry<Integer, List<Integer>> entry3 : map3.entrySet()) {
            RiskPointEvaluationItemAddBean itemAddBean = new RiskPointEvaluationItemAddBean();
            //风险点评估选项集合
            List<RiskPointEvaluationDetailAddBean> detailList = new ArrayList<>();
            List<RiskPointStableDetailBean> stableDetailList = new ArrayList<>();
            List<Integer> value = entry3.getValue();
            if (!CollectionUtils.isEmpty(value)) {
                int rowIndex = value.get(0);  //行索引
                if (!CollectionUtils.isEmpty(value) && value.size() > 1) {
                    String valueString = value.stream().map(e -> e + 1).map(String::valueOf).collect(Collectors.joining(","));
                    errorMessages.add(sheetName + ":第[" + valueString + "]行评估序号重复,只读取第" + (rowIndex + 1) + "行数据,其余忽略");
                }
                validRowList.add(rowIndex);
                row = sheet.getRow(rowIndex);
                if (row.getCell(pointCodeIndex) != null && getCellStringValue(row.getCell(pointCodeIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(pointCodeIndex)))) {
                    String pointCode = getCellStringValue(row.getCell(pointCodeIndex));
                    if (isNum(pointCode)) {
                        pointCode = getNumberString(pointCode);
                    }
                    riskPoint.setCode(pointCode);
                }
                //风险点名称
                if (row.getCell(pointCodeIndex + 1) == null || getCellStringValue(row.getCell(pointCodeIndex + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 1)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险单元名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }

                //岗位
                int jobIndex=controLevelIndex-12;
                //排查人员
                int userIndex=controLevelIndex-11;
         /*       if (row.getCell(jobIndex) == null || getCellStringValue(row.getCell(jobIndex)) == null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }*/
                BpJob bpJob;
                if (row.getCell(jobIndex) != null&&StringUtils.isNotBlank(row.getCell(jobIndex).toString())) {
                    bpJob = bpJobDao.findByName(row.getCell(jobIndex).toString());
                    if (bpJob==null){
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查岗位不存在");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }
                }
                if (row.getCell(userIndex) != null&&StringUtils.isNotBlank(row.getCell(userIndex).toString())) {
                    String[] userNames = row.getCell(userIndex).toString().split(",");
                    Integer noUser=0;
                    for (String userName : userNames) {
                        Integer num = baseUserDao.findByUserName(userName);
                        if (num<=0){
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,排查人员"+userName+"不存在");
                            safeRemoveFromList(validRowList, rowIndex);
                            noUser++;
                        }
                    }
                    if (noUser>0){
                        continue;
                    }
                }

                String pointName = getCellStringValue(row.getCell(pointCodeIndex + 1));
                if (isNum(pointName)) {
                    pointName = getNumberString(pointName);
                }
                riskPoint.setName(pointName);
                //风险点类型
                if (row.getCell(pointCodeIndex + 2) == null || getCellStringValue(row.getCell(pointCodeIndex + 2)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 2)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointTypeName = getCellStringValue(row.getCell(pointCodeIndex + 2));
                if (StringUtils.isBlank(pointTypeName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                List<RiskPointType> typeList = null;
                if (pointTypeMap != null && pointTypeMap.size() > 0) {
                    typeList = pointTypeMap.get(pointTypeName);
                }
                if (CollectionUtils.isEmpty(typeList)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型 " + pointTypeName + " 不正确");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                riskPoint.setType(typeList.get(0).getCode());
                //风险区域编码
                if (row.getCell(districtNameIndex) == null || getCellStringValue(row.getCell(districtNameIndex)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(districtNameIndex)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String districtName = getCellStringValue(row.getCell(districtNameIndex)).trim();
                if (isNum(districtName)) {
                    districtName = getNumberString(districtName);
                }
                if (StringUtils.isBlank(districtName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                } else {
                    List<RiskDistrict> dsts = null;
                    if (districtMap != null && districtMap.size() > 0) {
                        dsts = districtMap.get(districtName);
                    }
                    if (CollectionUtils.isEmpty(dsts)) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险区域名称[" + districtName + "]系统无此区域请先创建");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    } else {
                        if (!CollectionUtils.isEmpty(dsts)) {
                            List<Long> responsibleDepts = dsts.stream().map(RiskDistrict::getResponsibleDept).collect(toList());
                            List<Long> intersection = responsibleDepts.stream().filter(item -> deptIds.contains(Long.valueOf(item))).collect(toList());
                            if (CollectionUtils.isEmpty(intersection)) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,无权限导入该风险区域数据");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                        }
                        RiskDistrict d = riskDistrictDao.getByPointCode(riskPoint.getCode());
                        if (d != null && !d.getId().equals(dsts.get(0).getId())) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,该风险点已被其他风险区域关联");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                        riskPoint.setRiskDistrict(dsts.get(0));
                    }
                }

                if (row.getCell(evalUserIndex) != null && getCellStringValue(row.getCell(evalUserIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(evalUserIndex)))) {
                    String evaluationUserName = getCellStringValue(row.getCell(evalUserIndex)).replace("，", ",");
                    if (isNum(evaluationUserName)) {
                        evaluationUserName = getNumberString(evaluationUserName);
                    }
                    if (StringUtils.isBlank(evaluationUserName)) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人姓名不能为空");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    } else {
                        BaseUser evaluationUser = null;
                        List<String> nameStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(evaluationUserName);
                        List<Long> codeList = new ArrayList<>();
                        boolean isUserValid = true;
                        for (String name : nameStr) {
                            if (isNum(name)) {
                                name = getNumberString(name);
                            }
                            if (StringUtils.isNotBlank(name)) {
                                if (mapBean.getDuplicateNames().contains(name)) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人员姓名: " + name + ",有重名人员");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isUserValid = false;
                                    continue;
                                }
                                evaluationUser = mapBean.getUserNameMap().get(name);
                                if (evaluationUser == null) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人姓名" + name + "不存在");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    isUserValid = false;
                                    continue;
                                } else {
                                    riskPoint.setAuditUserId(evaluationUser.getId());
                                }
                            }
                            codeList.add(evaluationUser.getId());
                        }
                        // 评估人有无效工号，则整条数据无效
                        if (!isUserValid) {
                            continue;
                        }
                        riskPointEvaluationBusinessBean.setEvaluationUserIds(codeList);

                    }
                }

                //分析方法
                for (int i = 0; i < analyzeMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = analyzeMethodList.get(i);
                    //判断是否必填
                    if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                        if (row.getCell(itemIndex + i + 1) == null || getCellStringValue(row.getCell(itemIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的分析方法不可为空");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                    if (row.getCell(itemIndex + i + 1) != null && getCellStringValue(row.getCell(itemIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(0);
                        //选项id
                        detailAddBean.setMethodId(method.getId());
                        if (method.getContentType() != null && method.getContentType() == 1) {
                            //选项
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            //0文本,1下拉选
                            detailAddBean.setContentType(1);
                            if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                List<RiskEvaluationTargetItem> targetItemList = targetItemDao.findByNameAndTypeIds(content, evalTargetMap.get(method.getId()));
                                if (!CollectionUtils.isEmpty(targetItemList)) {
                                    Long targetItemId = targetItemList.get(0).getId();
                                    detailAddBean.setTargetItemId(targetItemId);
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        } else {
                            //文本
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            if (isNum(content)) {
                                content = getNumberString(content);
                            }
                            detailAddBean.setContentType(0);
                            detailAddBean.setContent(content);
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }

                }

                //固有评估
                if (stablePointContrFlag) {
                    Double stableScore = null;
                    int stableEvalNum = 0;
                    for (int i = 0; i < evaluationMethodList.size(); i++) {
                        RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                        if (method.getContentType() != null && method.getContentType() == 0) {
                            if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                                if (row.getCell(stableIndex + i + 1) == null || getCellStringValue(row.getCell(stableIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(stableIndex + i + 1)))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的固有评估方法不可为空");
                                    continue;
                                }
                            }
                            if (row.getCell(stableIndex + i + 1) != null && getCellStringValue(row.getCell(stableIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(stableIndex + i + 1)))) {
                                RiskPointStableDetailBean detailAddBean = new RiskPointStableDetailBean();
                                //类型:0分析方法选项,1评估方法选项,2数据字典
                                detailAddBean.setMethodAnalyzeType(1);
                                //选项id
                                detailAddBean.setMethodId(method.getId());
                                //选项
                                String content = getCellStringValue(row.getCell(stableIndex + i + 1));
                                //0乘数,1乘积
                                detailAddBean.setContentType(0);
                                if (isNum(content)) {
                                    content = getNumberString(content);
                                    if (stableScore == null) {
                                        stableScore = Double.valueOf(content);
                                    } else {
                                        stableScore = stableScore * Double.valueOf(content);
                                    }
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估方法只能填写数值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                                if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                    if (!CollectionUtils.isEmpty(items)) {
                                        detailAddBean.setTargetItemId(items.get(0).getId());
                                    } else {
                                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估方法未配置该分值");
                                        safeRemoveFromList(validRowList, rowIndex);
                                        continue;
                                    }
                                }

                                stableDetailList.add(detailAddBean);
                                stableRowDataMap.put(rowIndex, stableDetailList);
                                stableEvalNum++;
                            }
                        }
                    }
                    if (stableEvalNum < 1) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,固有评估选项至少填写一项");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }
                    if (stableScore == null) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的固有评估选项");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }

                    if (evalyationWay != null) {
                        if (stableScore < evalyationWay.getLowRisk() || stableScore.equals(evalyationWay.getLowRisk())) {
                            stableRiskLevel = 4;
                        } else if (stableScore > evalyationWay.getLowRisk() && (stableScore < evalyationWay.getGeneralRisk() || stableScore.equals(evalyationWay.getGeneralRisk()))) {
                            stableRiskLevel = 3;
                        } else if (stableScore > evalyationWay.getGeneralRisk() && (stableScore < evalyationWay.getHigherRisk() || stableScore.equals(evalyationWay.getHigherRisk()))) {
                            stableRiskLevel = 2;
                        } else if (stableScore > evalyationWay.getHigherRisk()) {
                            stableRiskLevel = 1;
                        }
                    }
                    if (stableBusinessRiskLevel == null) {
                        stableBusinessRiskLevel = stableRiskLevel;
                    } else {
                        if (stableBusinessRiskLevel > stableRiskLevel) {
                            stableBusinessRiskLevel = stableRiskLevel;
                        }
                    }
                    //乘积
                    for (int i = 0; i < evaluationMethodList.size(); i++) {
                        RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                        if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                            RiskPointStableDetailBean detailAddBean = new RiskPointStableDetailBean();
                            detailAddBean.setMethodAnalyzeType(1);
                            detailAddBean.setMethodId(method.getId());
                            detailAddBean.setContentType(1);
                            BigDecimal bg = new BigDecimal(stableScore);
                            double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            detailAddBean.setContent(doubleValue + "");
                            stableDetailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }
                }

                //控制评估方法
                Double score = null;
                int evalNum = 0;
                boolean evalFlag = true;
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType() == 0) {
                        if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                            if (row.getCell(controlIndex + i + 1) == null || getCellStringValue(row.getCell(controlIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(controlIndex + i + 1)))) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的评估方法不可为空");
                                continue;
                            }
                        }
                        if (row.getCell(controlIndex + i + 1) != null && getCellStringValue(row.getCell(controlIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(controlIndex + i + 1)))) {
                            RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                            //类型:0分析方法选项,1评估方法选项,2数据字典
                            detailAddBean.setMethodAnalyzeType(1);
                            //选项id
                            detailAddBean.setMethodId(method.getId());
                            //选项
                            String content = getCellStringValue(row.getCell(controlIndex + i + 1));
                            //0乘数,1乘积
                            detailAddBean.setContentType(0);
                            if (isNum(content)) {
                                content = getNumberString(content);
                                if (score == null) {
                                    score = Double.valueOf(content);
                                } else {
                                    score = score * Double.valueOf(content);
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法只能填写数值");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                            if (evalTargetMap != null) {
                                if (CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请完善配置项[" + method.getName() + "]中的配置");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    evalFlag = false;
                                    continue;
                                }
                                List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                if (!CollectionUtils.isEmpty(items)) {
                                    detailAddBean.setTargetItemId(items.get(0).getId());
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法未配置该分值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                            evalNum++;
                        }
                    }
                }
                if (evalNum < 1 && evalFlag) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估选项至少填写一项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                if (score == null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的评估选项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }

                if (evalyationWay != null) {
                    if (score < evalyationWay.getLowRisk() || score.equals(evalyationWay.getLowRisk())) {
                        riskLevel = 4;
                    } else if (score > evalyationWay.getLowRisk() && (score < evalyationWay.getGeneralRisk() || score.equals(evalyationWay.getGeneralRisk()))) {
                        riskLevel = 3;
                    } else if (score > evalyationWay.getGeneralRisk() && (score < evalyationWay.getHigherRisk() || score.equals(evalyationWay.getHigherRisk()))) {
                        riskLevel = 2;
                    } else if (score > evalyationWay.getHigherRisk()) {
                        riskLevel = 1;
                    }
                }
                if (businessRiskLevel == null) {
                    businessRiskLevel = riskLevel;
                } else {
                    if (businessRiskLevel > riskLevel) {
                        businessRiskLevel = riskLevel;
                    }
                }
                //乘积
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        detailAddBean.setMethodAnalyzeType(1);
                        detailAddBean.setMethodId(method.getId());
                        detailAddBean.setContentType(1);
                        BigDecimal bg = new BigDecimal(score);
                        double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        detailAddBean.setContent(doubleValue + "");
                        detailList.add(detailAddBean);
                        rowDataMap.put(rowIndex, detailList);
                    }
                }
                itemAddBean.setRiskLevel(riskLevel);
                itemAddBean.setStableRiskLevel(stableRiskLevel);
                //安全措施+风险分级管控
                boolean isDataValid = true;
                //风险分级管控
                //责任人工号
                List<Long> responseUserIds = new ArrayList<>();
                //责任部门单位
                List<Long> responseDepartIds = new ArrayList<>();
                //管控层级
                List<Long> controlLevelIds = new ArrayList<>();
                //取数来源id
                Long accessSourceId = null;
                //管控状态
                Integer controlorState = null;
                //排查人员 key:岗位id value 人员集合
                Map<Long, List<BaseUser>> checkJobMap = new LinkedHashMap<>();
                //排查频率
                List<Integer> periodDaysList = new ArrayList<>();
                //排查周期
                String periodUnits = null;
                //隐患问题描述
                String hiddenDangersDesc = null;
                //排查计划备注
                String planRemark = null;
                // 排查计划岗位集合
                List<Long> investigateJobIds = new ArrayList<>();
                int controlNum = 0;
                if (row.getCell(resDepartIndex) != null && getCellStringValue(row.getCell(resDepartIndex)) != null &&
                        StringUtils.isNotBlank(getCellStringValue(row.getCell(resDepartIndex)))) {
                    String responseDepartNames = getCellStringValue(row.getCell(resDepartIndex)).replace("，", ",");
                    List<String> namesStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(responseDepartNames).stream().distinct().collect(toList());
                    isDataValid = true;
                    if (namesStr.size() > 10) {
                        errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请不要填写10个以上的责任单位");
                        safeRemoveFromList(validRowList, rowIndex);
                        isDataValid = false;
                        continue;
                    }
                    for (String name : namesStr) {
                        if (isNum(name)) {
                            name = getNumberString(name);
                        }
                        if (StringUtils.isNotBlank(name)) {
                            BpDepart responseDepart = null;
                            if (mapBean.getDupDepartNames().contains(name)) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任单位[" + name + "]名称已存在");
                                safeRemoveFromList(validRowList, rowIndex);
                                isDataValid = false;
                                continue;
                            }
                            if (departMap != null && departMap.size() > 0) {
                                responseDepart = departMap.get(name);
                            }
                            if (responseDepart != null) {
                                if (!responseDepartIds.contains(responseDepart.getId())) {
                                    responseDepartIds.add(responseDepart.getId());
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,责任单位[" + name + "]不存在");
                                safeRemoveFromList(validRowList, rowIndex);
                                isDataValid = false;
                                continue;
                            }
                        }
                    }
                    if (!isDataValid) {
                        continue;
                    }
                    if (responseDepartIds.size() > 0) {
                        controlNum++;
                    }
                }

                if (row.getCell(controLevelIndex) != null && getCellStringValue(row.getCell(controLevelIndex)) != null &&
                        StringUtils.isNotBlank(getCellStringValue(row.getCell(controLevelIndex)))) {
                    String controlLevel = getCellStringValue(row.getCell(controLevelIndex)).replace("，", ",");
                    isDataValid = true;
                    if (StringUtils.isNotBlank(controlLevel)) {
                        // 管控层级多选
                        List<String> levels = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(controlLevel);
                        for (String level : levels) {
                            Long levelId = mapBean.getControlLevelMap().get(level.trim());
                            if (levelId != null) {
                                if (!controlLevelIds.contains(levelId)) {
                                    controlLevelIds.add(levelId);
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控层级" + level + "不存在");
                                safeRemoveFromList(validRowList, rowIndex);
                                isDataValid = false;
                                continue;
                            }
                        }
                    }

                    if (!isDataValid) {
                        continue;
                    }
                    if (controlLevelIds.size() > 0) {
                        controlNum++;
                    }
                }
                if (controlNum == 0) {
                    controlorState = 1;
                } else if (controlNum == 2) {
                    controlorState = 2;
                } else {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请正确填写责任单位编码,管控级别");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                int measureCount = 0;
                String content = null;
                isDataValid = true;
                for (int i = 0; i < mapBean.getTopTypes().size(); i++) {
                    RiskMeasureType riskMeasureType = mapBean.getTopTypes().get(i);
                    if (row.getCell(measureTypeIndex + i + 1) != null && getCellStringValue(row.getCell(measureTypeIndex + i + 1)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(measureTypeIndex + i + 1)))) {
                        mapBean.setMeasureTypeId(riskMeasureType.getId());
                        content = getCellStringValue(row.getCell(measureTypeIndex + i + 1));
                        if (isNum(content)) {
                            content = getNumberString(content);
                        }
                        if (content.length() > 2000) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控措施[" + mapBean.getTopTypes().get(i).getMeasureTypeName() + "]填写内容不能超过2000个字");
                            safeRemoveFromList(validRowList, rowIndex);
                            isDataValid = false;
                            continue;
                        }
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(2);
                        detailAddBean.setContentType(0);
                        detailAddBean.setMethodId(mapBean.getMeasureTypeId());
                        detailAddBean.setContent(content);
                        detailAddBean.setControlLevelIds(controlLevelIds);
                        detailAddBean.setResponseUserIds(responseUserIds);
                        detailAddBean.setResponseDepartIds(responseDepartIds);
                        detailAddBean.setControlState(controlorState);
                        detailList.add(detailAddBean);
                        measureCount++;
                    }
                }
                if (!isDataValid) {
                    continue;
                }
                if (measureCount < 1) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控措施至少填写一列");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                rowDataMap.put(rowIndex, detailList);
            }
            //根据数据校验结果，保存有效数据行内容
            if (validRowList.size() > 0) {
                for (Integer r : validRowList) {
                    itemAddBean.setDetailList(rowDataMap.get(r));
                    itemAddBean.setStableDetailList(stableRowDataMap.get(r));
                    itemList.add(itemAddBean);
                }
                validRowList.clear();
            }
        }
        excelMapData.setItemList(itemList);
        excelMapData.setBusinessRiskLevel(businessRiskLevel);
        excelMapData.setStableBusinessRiskLevel(stableBusinessRiskLevel);
        // 评估内容为空时， 风险点信息不做导入
        if (itemList != null && !itemList.isEmpty()) {
            excelMapData.setPointCode(riskPoint.getCode());
        }
        return excelMapData;
    }

    private RiskExcelMapDataBean batchRiskPointLibraryEvaluationImport(XSSFSheet sheet, Map<Integer, List<Integer>> map3, List<String> errorMessages,
                                                                       RiskPoint riskPoint, RiskEvaluationAnalyzeWay evalyationWay,
                                                                       List<RiskEvaluationAnalyzeMethod> analyzeMethodList, List<RiskEvaluationAnalyzeMethod> evaluationMethodList,
                                                                       RiskPointEvaluationBusinessBean riskPointEvaluationBusinessBean, Integer businessRiskLevel, Integer stableBusinessRiskLevel,
                                                                       Integer pointCodeIndex, Integer itemIndex, Integer evaluationTimeIndex, List<RiskPointEvaluationItemAddBean> itemList,
                                                                       RiskEvaluationExcelMapBean mapBean) {
        Map<String, BaseUser> userMap = mapBean.getUserMap();
        Map<String, List<RiskPointType>> pointTypeMap = mapBean.getPointTypeMap();
        Map<Long, List<Long>> evalTargetMap = mapBean.getEvalTargetMap();
        RiskExcelMapDataBean excelMapData = new RiskExcelMapDataBean();
        String sheetName = sheet.getSheetName();
        //隐患排查内容
        String hiddenDangerContent = null;
        XSSFRow row = null;
        Integer riskLevel = null;
        Integer stableRiskLevel = null;
        Map<Integer, List<RiskPointEvaluationDetailAddBean>> rowDataMap = new HashMap<>();
        List<Integer> validRowList = new ArrayList<>();
        for (Map.Entry<Integer, List<Integer>> entry3 : map3.entrySet()) {
            RiskPointEvaluationItemAddBean itemAddBean = new RiskPointEvaluationItemAddBean();
            //风险点评估选项集合
            List<RiskPointEvaluationDetailAddBean> detailList = new ArrayList<>();
            List<Integer> value = entry3.getValue();
            if (!CollectionUtils.isEmpty(value)) {
                int rowIndex = value.get(0);  //行索引
                validRowList.add(rowIndex);
                row = sheet.getRow(rowIndex);
                if (row.getCell(pointCodeIndex) != null && getCellStringValue(row.getCell(pointCodeIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(pointCodeIndex)))) {
                    String pointCode = getCellStringValue(row.getCell(pointCodeIndex));
                    if (isNum(pointCode)) {
                        pointCode = getNumberString(pointCode);
                    }
                    riskPoint.setCode(pointCode);
                }
                //风险点名称
                if (row.getCell(pointCodeIndex + 1) == null || getCellStringValue(row.getCell(pointCodeIndex + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 1)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险单元名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointName = getCellStringValue(row.getCell(pointCodeIndex + 1));
                if (isNum(pointName)) {
                    pointName = getNumberString(pointName);
                }
                riskPoint.setName(pointName);
                //风险点类型
                if (row.getCell(pointCodeIndex + 2) == null || getCellStringValue(row.getCell(pointCodeIndex + 2)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 2)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointTypeName = getCellStringValue(row.getCell(pointCodeIndex + 2));
                if (StringUtils.isBlank(pointTypeName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                List<RiskPointType> typeList = null;
                if (pointTypeMap != null && pointTypeMap.size() > 0) {
                    typeList = pointTypeMap.get(pointTypeName);
                }
                if (CollectionUtils.isEmpty(typeList)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型 " + pointTypeName + " 不正确");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                riskPoint.setType(typeList.get(0).getCode());

                if (row.getCell(evaluationTimeIndex - 2) == null || getCellStringValue(row.getCell(evaluationTimeIndex - 2)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(evaluationTimeIndex - 2)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String evaluationUserCode = getCellStringValue(row.getCell(evaluationTimeIndex - 2)).replace("，", ",");
                if (isNum(evaluationUserCode)) {
                    evaluationUserCode = getNumberString(evaluationUserCode);
                }
                if (StringUtils.isBlank(evaluationUserCode)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                } else {
                    BaseUser evaluationUser = null;
                    List<String> codesStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(evaluationUserCode);
                    List<Long> codeList = new ArrayList<>();
                    boolean isUserValid = true;
                    for (String code : codesStr) {
                        if (isNum(code)) {
                            code = getNumberString(code);
                        }
                        if (StringUtils.isNotBlank(code)) {
                            if (userMap != null && userMap.size() > 0) {
                                evaluationUser = userMap.get(code);
                            }
                            if (evaluationUser == null) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号" + code + "不存在");
                                safeRemoveFromList(validRowList, rowIndex);
                                isUserValid = false;
                                continue;
                            } else {
                                riskPoint.setAuditUserId(evaluationUser.getId());
                            }
                        }
                        codeList.add(evaluationUser.getId());
                    }
                    // 评估人有无效工号，则整条数据无效
                    if (!isUserValid) {
                        continue;
                    }
                    riskPointEvaluationBusinessBean.setEvaluationUserIds(codeList);

                }

                //分析方法
                for (int i = 0; i < analyzeMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = analyzeMethodList.get(i);
                    //判断是否必填
                    if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                        if (row.getCell(itemIndex + i + 1) == null || getCellStringValue(row.getCell(itemIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的分析方法不可为空");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                    if (row.getCell(itemIndex + i + 1) != null && getCellStringValue(row.getCell(itemIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(0);
                        //选项id
                        detailAddBean.setMethodId(method.getId());
                        if (method.getContentType() != null && method.getContentType() == 1) {
                            //选项
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            //0文本,1下拉选
                            detailAddBean.setContentType(1);
                            if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                List<RiskEvaluationTargetItem> targetItemList = targetItemDao.findByNameAndTypeIds(content, evalTargetMap.get(method.getId()));
                                if (!CollectionUtils.isEmpty(targetItemList)) {
                                    Long targetItemId = targetItemList.get(0).getId();
                                    detailAddBean.setTargetItemId(targetItemId);
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        } else {
                            //文本
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            if (isNum(content)) {
                                content = getNumberString(content);
                            }
                            detailAddBean.setContentType(0);
                            detailAddBean.setContent(content);
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }

                }
                int cellIndex = itemIndex + analyzeMethodList.size();

                //控制评估方法
                Double score = null;
                int evalNum = 0;
                boolean evalFlag = true;
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType() == 0) {
                        if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                            if (row.getCell(cellIndex + i + 1) == null || getCellStringValue(row.getCell(cellIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(cellIndex + i + 1)))) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的评估方法不可为空");
                                continue;
                            }
                        }
                        if (row.getCell(cellIndex + i + 1) != null && getCellStringValue(row.getCell(cellIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(cellIndex + i + 1)))) {
                            RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                            //类型:0分析方法选项,1评估方法选项,2数据字典
                            detailAddBean.setMethodAnalyzeType(1);
                            //选项id
                            detailAddBean.setMethodId(method.getId());
                            //选项
                            String content = getCellStringValue(row.getCell(cellIndex + i + 1));
                            //0乘数,1乘积
                            detailAddBean.setContentType(0);
                            if (isNum(content)) {
                                content = getNumberString(content);
                                if (score == null) {
                                    score = Double.valueOf(content);
                                } else {
                                    score = score * Double.valueOf(content);
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法只能填写数值");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                            if (evalTargetMap != null) {
                                if (CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请完善配置项[" + method.getName() + "]中的配置");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    evalFlag = false;
                                    continue;
                                }
                                List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                if (!CollectionUtils.isEmpty(items)) {
                                    detailAddBean.setTargetItemId(items.get(0).getId());
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法未配置该分值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                            }

                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                            evalNum++;
                        }
                    }
                }
                if (evalNum < 1 && evalFlag) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估选项至少填写一项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                if (score == null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的评估选项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }

                if (evalyationWay != null) {
                    if (score < evalyationWay.getLowRisk() || score.equals(evalyationWay.getLowRisk())) {
                        riskLevel = 4;
                    } else if (score > evalyationWay.getLowRisk() && (score < evalyationWay.getGeneralRisk() || score.equals(evalyationWay.getGeneralRisk()))) {
                        riskLevel = 3;
                    } else if (score > evalyationWay.getGeneralRisk() && (score < evalyationWay.getHigherRisk() || score.equals(evalyationWay.getHigherRisk()))) {
                        riskLevel = 2;
                    } else if (score > evalyationWay.getHigherRisk()) {
                        riskLevel = 1;
                    }
                }
                if (businessRiskLevel == null) {
                    businessRiskLevel = riskLevel;
                } else {
                    if (businessRiskLevel > riskLevel) {
                        businessRiskLevel = riskLevel;
                    }
                }
                //乘积
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        detailAddBean.setMethodAnalyzeType(1);
                        detailAddBean.setMethodId(method.getId());
                        detailAddBean.setContentType(1);
                        BigDecimal bg = new BigDecimal(score);
                        double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        detailAddBean.setContent(doubleValue + "");
                        detailList.add(detailAddBean);
                        rowDataMap.put(rowIndex, detailList);
                    }
                }

                itemAddBean.setRiskLevel(riskLevel);
                itemAddBean.setStableRiskLevel(stableRiskLevel);
                //安全措施+风险分级管控
                boolean isDataValid = true;
                for (Integer inte : value) {
                    row = sheet.getRow(inte);
                    rowIndex = inte;
                    //风险分级管控
                    //责任人工号
                    List<Long> responseUserIds = new ArrayList<>();
                    //责任部门单位
                    List<Long> responseDepartIds = new ArrayList<>();
                    //管控层级
                    List<Long> controlLevelIds = new ArrayList<>();
                    //取数来源id
                    Long accessSourceId = null;
                    //管控状态
                    Integer controlorState = null;
                    //排查人员 key:岗位id value 人员集合
                    Map<Long, List<BaseUser>> checkJobMap = new LinkedHashMap<>();
                    //排查频率
                    List<Integer> periodDaysList = new ArrayList<>();
                    //排查周期
                    String periodUnits = null;
                    //隐患问题描述
                    String hiddenDangersDesc = null;
                    //排查计划备注
                    String planRemark = null;
                    // 排查计划岗位集合
                    List<Long> investigateJobIds = new ArrayList<>();

                    //管控措施
                    int measureTypeIndex = itemIndex + analyzeMethodList.size() + evaluationMethodList.size();
                    //一级管理措施类型
                    if (checkNullCell(row, measureTypeIndex + 1)) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 管控措施类型不能为空");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }

                    Map<String, BaseTypeGroupItem> controlTypeGroupItemNameMap = mapBean.getControlTypeGroupItemNameMap();
                    String firstTypeName = getCellStringValue(row.getCell(measureTypeIndex + 1)).toString().trim();
                    BaseTypeGroupItem firstType = controlTypeGroupItemNameMap.get(firstTypeName);
                    if (firstType == null) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 管控措施类型不存在，请检查数据或配置管控措施类型后再导入");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }
                    //默认存放管控类型一级ID
                    mapBean.setMeasureTypeId(firstType.getId());
                    int measureContentIndex = measureTypeIndex + mapBean.getMaxTypeLevel();
                    if (checkNullCell(row, measureContentIndex + 1)) {
                        errorMessages.add(sheetName + ":第" + (inte + 1) + "行 管控措施内容不能为空");
                        safeRemoveFromList(validRowList, rowIndex);
                        continue;
                    }
                    detailList = builderDetailAddBean(detailList, mapBean, getCellStringValue(row.getCell(measureContentIndex + 1)), controlLevelIds, responseUserIds, responseDepartIds, controlorState,
                            hiddenDangerContent, accessSourceId, null, hiddenDangersDesc, planRemark, checkJobMap, periodUnits, periodDaysList,null,null,null, investigateJobIds);
                    rowDataMap.put(inte, detailList);
                }
            }
            //根据数据校验结果，保存有效数据行内容
            if (validRowList.size() > 0) {
                for (Integer r : validRowList) {
                    itemAddBean.setDetailList(rowDataMap.get(r));
                    itemList.add(itemAddBean);
                }
                validRowList.clear();
            }
        }
        excelMapData.setItemList(itemList);
        excelMapData.setBusinessRiskLevel(businessRiskLevel);
        excelMapData.setStableBusinessRiskLevel(stableBusinessRiskLevel);
        // 评估内容为空时， 风险点信息不做导入
        if (itemList != null && !itemList.isEmpty()) {
            excelMapData.setPointCode(riskPoint.getCode());
        }
        return excelMapData;
    }

    private RiskExcelMapDataBean batchStorePointLibraryEvaluationImport(XSSFSheet sheet, Map<Integer, List<Integer>> map3, List<String> errorMessages,
                                                                        RiskPoint riskPoint, RiskEvaluationAnalyzeWay evalyationWay,
                                                                        List<RiskEvaluationAnalyzeMethod> analyzeMethodList, List<RiskEvaluationAnalyzeMethod> evaluationMethodList,
                                                                        RiskPointEvaluationBusinessBean riskPointEvaluationBusinessBean, Integer businessRiskLevel, Integer stableBusinessRiskLevel,
                                                                        Integer pointCodeIndex, Integer itemIndex, Integer evaluationTimeIndex, List<RiskPointEvaluationItemAddBean> itemList,
                                                                        RiskEvaluationExcelMapBean mapBean) {
        Map<String, BaseUser> userMap = mapBean.getUserMap();
        Map<String, List<RiskPointType>> pointTypeMap = mapBean.getPointTypeMap();
        Map<Long, List<Long>> evalTargetMap = mapBean.getEvalTargetMap();
        RiskExcelMapDataBean excelMapData = new RiskExcelMapDataBean();
        String sheetName = sheet.getSheetName();
        int measureTypeIndex = itemIndex + analyzeMethodList.size() + evaluationMethodList.size();
        XSSFRow row = null;
        Integer riskLevel = null;
        Integer stableRiskLevel = null;
        Map<Integer, List<RiskPointEvaluationDetailAddBean>> rowDataMap = new HashMap<>();
        List<Integer> validRowList = new ArrayList<>();
        for (Map.Entry<Integer, List<Integer>> entry3 : map3.entrySet()) {
            RiskPointEvaluationItemAddBean itemAddBean = new RiskPointEvaluationItemAddBean();
            //风险点评估选项集合
            List<RiskPointEvaluationDetailAddBean> detailList = new ArrayList<>();
            List<Integer> value = entry3.getValue();
            if (!CollectionUtils.isEmpty(value)) {
                int rowIndex = value.get(0);  //行索引
                if (!CollectionUtils.isEmpty(value) && value.size() > 1) {
                    String valueString = value.stream().map(e -> e + 1).map(String::valueOf).collect(Collectors.joining(","));
                    errorMessages.add(sheetName + ":第[" + valueString + "]行评估序号重复,只读取第" + (rowIndex + 1) + "行数据,其余忽略");
                }
                validRowList.add(rowIndex);
                row = sheet.getRow(rowIndex);
                if (row.getCell(pointCodeIndex) != null && getCellStringValue(row.getCell(pointCodeIndex)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(pointCodeIndex)))) {
                    String pointCode = getCellStringValue(row.getCell(pointCodeIndex));
                    if (isNum(pointCode)) {
                        pointCode = getNumberString(pointCode);
                    }
                    riskPoint.setCode(pointCode);
                }
                //风险点名称
                if (row.getCell(pointCodeIndex + 1) == null || getCellStringValue(row.getCell(pointCodeIndex + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 1)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险单元名称不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointName = getCellStringValue(row.getCell(pointCodeIndex + 1));
                if (isNum(pointName)) {
                    pointName = getNumberString(pointName);
                }
                riskPoint.setName(pointName);
                //风险点类型
                if (row.getCell(pointCodeIndex + 2) == null || getCellStringValue(row.getCell(pointCodeIndex + 2)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointCodeIndex + 2)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String pointTypeName = getCellStringValue(row.getCell(pointCodeIndex + 2));
                if (StringUtils.isBlank(pointTypeName)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                List<RiskPointType> typeList = null;
                if (pointTypeMap != null && pointTypeMap.size() > 0) {
                    typeList = pointTypeMap.get(pointTypeName);
                }
                if (CollectionUtils.isEmpty(typeList)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,风险点类型 " + pointTypeName + " 不正确");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                riskPoint.setType(typeList.get(0).getCode());

                if (row.getCell(evaluationTimeIndex - 2) == null || getCellStringValue(row.getCell(evaluationTimeIndex - 2)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(evaluationTimeIndex - 2)))) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                String evaluationUserCode = getCellStringValue(row.getCell(evaluationTimeIndex - 2)).replace("，", ",");
                if (isNum(evaluationUserCode)) {
                    evaluationUserCode = getNumberString(evaluationUserCode);
                }
                if (StringUtils.isBlank(evaluationUserCode)) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号不能为空");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                } else {
                    BaseUser evaluationUser = null;
                    List<String> codesStr = Splitter.on(Constant.SPLIT_COMMA).trimResults().splitToList(evaluationUserCode);
                    List<Long> codeList = new ArrayList<>();
                    boolean isUserValid = true;
                    for (String code : codesStr) {
                        if (isNum(code)) {
                            code = getNumberString(code);
                        }
                        if (StringUtils.isNotBlank(code)) {
                            if (userMap != null && userMap.size() > 0) {
                                evaluationUser = userMap.get(code);
                            }
                            if (evaluationUser == null) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估人工号" + code + "不存在");
                                safeRemoveFromList(validRowList, rowIndex);
                                isUserValid = false;
                                continue;
                            } else {
                                riskPoint.setAuditUserId(evaluationUser.getId());
                            }
                        }
                        codeList.add(evaluationUser.getId());
                    }
                    // 评估人有无效工号，则整条数据无效
                    if (!isUserValid) {
                        continue;
                    }
                    riskPointEvaluationBusinessBean.setEvaluationUserIds(codeList);

                }

                //分析方法
                for (int i = 0; i < analyzeMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = analyzeMethodList.get(i);
                    //判断是否必填
                    if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                        if (row.getCell(itemIndex + i + 1) == null || getCellStringValue(row.getCell(itemIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的分析方法不可为空");
                            safeRemoveFromList(validRowList, rowIndex);
                            continue;
                        }
                    }
                    if (row.getCell(itemIndex + i + 1) != null && getCellStringValue(row.getCell(itemIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(itemIndex + i + 1)))) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(0);
                        //选项id
                        detailAddBean.setMethodId(method.getId());
                        if (method.getContentType() != null && method.getContentType() == 1) {
                            //选项
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            //0文本,1下拉选
                            detailAddBean.setContentType(1);
                            if (evalTargetMap != null && !CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                List<RiskEvaluationTargetItem> targetItemList = targetItemDao.findByNameAndTypeIds(content, evalTargetMap.get(method.getId()));
                                if (!CollectionUtils.isEmpty(targetItemList)) {
                                    Long targetItemId = targetItemList.get(0).getId();
                                    detailAddBean.setTargetItemId(targetItemId);
                                }
                            }
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        } else {
                            //文本
                            String content = getCellStringValue(row.getCell(itemIndex + i + 1));
                            if (isNum(content)) {
                                content = getNumberString(content);
                            }
                            detailAddBean.setContentType(0);
                            detailAddBean.setContent(content);
                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                        }
                    }

                }
                int cellIndex = itemIndex + analyzeMethodList.size();

                //控制评估方法
                Double score = null;
                int evalNum = 0;
                boolean evalFlag = true;
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType() == 0) {
                        if (method.getIsRequired() != null && method.getIsRequired().intValue() == 1) {
                            if (row.getCell(cellIndex + i + 1) == null || getCellStringValue(row.getCell(cellIndex + i + 1)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(cellIndex + i + 1)))) {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,必填的评估方法不可为空");
                                continue;
                            }
                        }
                        if (row.getCell(cellIndex + i + 1) != null && getCellStringValue(row.getCell(cellIndex + i + 1)) != null && StringUtils.isNotBlank(getCellStringValue(row.getCell(cellIndex + i + 1)))) {
                            RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                            //类型:0分析方法选项,1评估方法选项,2数据字典
                            detailAddBean.setMethodAnalyzeType(1);
                            //选项id
                            detailAddBean.setMethodId(method.getId());
                            //选项
                            String content = getCellStringValue(row.getCell(cellIndex + i + 1));
                            //0乘数,1乘积
                            detailAddBean.setContentType(0);
                            if (isNum(content)) {
                                content = getNumberString(content);
                                if (score == null) {
                                    score = Double.valueOf(content);
                                } else {
                                    score = score * Double.valueOf(content);
                                }
                            } else {
                                errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法只能填写数值");
                                safeRemoveFromList(validRowList, rowIndex);
                                continue;
                            }
                            if (evalTargetMap != null) {
                                if (CollectionUtils.isEmpty(evalTargetMap.get(method.getId()))) {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请完善配置项[" + method.getName() + "]中的配置");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    evalFlag = false;
                                    continue;
                                }
                                List<RiskEvaluationTargetItem> items = targetItemDao.findByTypeIdsAndScore(evalTargetMap.get(method.getId()), Double.valueOf(content));
                                if (!CollectionUtils.isEmpty(items)) {
                                    detailAddBean.setTargetItemId(items.get(0).getId());
                                } else {
                                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估方法未配置该分值");
                                    safeRemoveFromList(validRowList, rowIndex);
                                    continue;
                                }
                            }

                            detailList.add(detailAddBean);
                            rowDataMap.put(rowIndex, detailList);
                            evalNum++;
                        }
                    }
                }
                if (evalNum < 1 && evalFlag) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,评估选项至少填写一项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                if (score == null) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,请填写正确的评估选项");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }

                if (evalyationWay != null) {
                    if (score < evalyationWay.getLowRisk() || score.equals(evalyationWay.getLowRisk())) {
                        riskLevel = 4;
                    } else if (score > evalyationWay.getLowRisk() && (score < evalyationWay.getGeneralRisk() || score.equals(evalyationWay.getGeneralRisk()))) {
                        riskLevel = 3;
                    } else if (score > evalyationWay.getGeneralRisk() && (score < evalyationWay.getHigherRisk() || score.equals(evalyationWay.getHigherRisk()))) {
                        riskLevel = 2;
                    } else if (score > evalyationWay.getHigherRisk()) {
                        riskLevel = 1;
                    }
                }
                if (businessRiskLevel == null) {
                    businessRiskLevel = riskLevel;
                } else {
                    if (businessRiskLevel > riskLevel) {
                        businessRiskLevel = riskLevel;
                    }
                }
                //乘积
                for (int i = 0; i < evaluationMethodList.size(); i++) {
                    RiskEvaluationAnalyzeMethod method = evaluationMethodList.get(i);
                    if (method.getContentType() != null && method.getContentType().intValue() == 1) {
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        detailAddBean.setMethodAnalyzeType(1);
                        detailAddBean.setMethodId(method.getId());
                        detailAddBean.setContentType(1);
                        BigDecimal bg = new BigDecimal(score);
                        double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        detailAddBean.setContent(doubleValue + "");
                        detailList.add(detailAddBean);
                        rowDataMap.put(rowIndex, detailList);
                    }
                }

                itemAddBean.setRiskLevel(riskLevel);
                itemAddBean.setStableRiskLevel(stableRiskLevel);
                //安全措施+风险分级管控
                boolean isDataValid = true;
                row = sheet.getRow(rowIndex);

                //风险分级管控
                //责任人工号
                List<Long> responseUserIds = new ArrayList<>();
                //责任部门单位
                List<Long> responseDepartIds = new ArrayList<>();
                //管控层级
                List<Long> controlLevelIds = new ArrayList<>();
                //取数来源id
                Long accessSourceId = null;
                //管控状态
                Integer controlorState = null;
                //排查人员 key:岗位id value 人员集合
                Map<Long, List<BaseUser>> checkJobMap = new LinkedHashMap<>();
                //排查频率
                List<Integer> periodDaysList = new ArrayList<>();
                //排查周期
                String periodUnits = null;
                //隐患问题描述
                String hiddenDangersDesc = null;
                //排查计划备注
                String planRemark = null;
                // 排查计划岗位集合
                List<Long> investigateJobIds = new ArrayList<>();
                int measureCount = 0;
                String content = null;
                isDataValid = true;
                for (int i = 0; i < mapBean.getControlTypeGroupItemList().size(); i++) {
                    BaseTypeGroupItem item = mapBean.getControlTypeGroupItemList().get(i);
                    if (row.getCell(measureTypeIndex + i + 1) != null && getCellStringValue(row.getCell(measureTypeIndex + i + 1)) != null &&
                            StringUtils.isNotBlank(getCellStringValue(row.getCell(measureTypeIndex + i + 1)))) {
                        mapBean.setMeasureTypeId(item.getId());
                        content = getCellStringValue(row.getCell(measureTypeIndex + i + 1));
                        if (isNum(content)) {
                            content = getNumberString(content);
                        }
                        if (content.length() > 2000) {
                            errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控措施[" + item.getName() + "]填写内容不能超过2000个字");
                            safeRemoveFromList(validRowList, rowIndex);
                            isDataValid = false;
                            continue;
                        }
                        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                        //类型:0分析方法选项,1评估方法选项,2数据字典
                        detailAddBean.setMethodAnalyzeType(2);
                        detailAddBean.setContentType(0);
                        detailAddBean.setMethodId(item.getId());
                        detailAddBean.setContent(content);
                        detailList.add(detailAddBean);
                        measureCount++;
                    }
                }
                if (!isDataValid) {
                    continue;
                }
                if (measureCount < 1) {
                    errorMessages.add(sheetName + ":第" + (rowIndex + 1) + "行,管控措施至少填写一列");
                    safeRemoveFromList(validRowList, rowIndex);
                    continue;
                }
                rowDataMap.put(rowIndex, detailList);
            }
            //根据数据校验结果，保存有效数据行内容
            if (validRowList.size() > 0) {
                for (Integer r : validRowList) {
                    itemAddBean.setDetailList(rowDataMap.get(r));
                    itemList.add(itemAddBean);
                }
                validRowList.clear();
            }
        }
        excelMapData.setItemList(itemList);
        excelMapData.setBusinessRiskLevel(businessRiskLevel);
        excelMapData.setStableBusinessRiskLevel(stableBusinessRiskLevel);
        // 评估内容为空时， 风险点信息不做导入
        if (itemList != null && !itemList.isEmpty()) {
            excelMapData.setPointCode(riskPoint.getCode());
        }
        return excelMapData;
    }

    private RiskPoint addPoint(RiskPoint riskPoint, RiskEvaluationExcelMapBean mapBean) throws Exception {
        riskPoint.setSignInMethod(SignInMethodEnum.NOT_SIGN_IN.getCode());
        if (StringUtils.isBlank(riskPoint.getCode())) {
            riskPoint.setCode(bizCodeGeneratorFacade.fengXianDian());
        }
        //审核人默认当前人
        riskPoint.setAuditUserId(Context.getCurrentUserId());
        RiskPoint add = riskPointService.add(riskPoint);
        //更新 mapBean
        Map<String, RiskPoint> pointCodeMap = mapBean.getPointCodeMap();
        pointCodeMap.put(add.getCode(), add);
        Map<String, RiskPoint> districtIdPointNameMap = mapBean.getDistrictIdPointNameMap();
        Long districtId = null;
        if ((add.getShared() == null || add.getShared() == 0) && add.getRiskDistrict() != null) {
            districtId = add.getRiskDistrict().getId();
        }
        districtIdPointNameMap.put(districtId + "_" + add.getShared() + "_" + add.getName(), add);
        mapBean.setPointCodeMap(pointCodeMap);
        mapBean.setDistrictIdPointNameMap(districtIdPointNameMap);
        return add;
    }

    private RiskPoint updatePoint(RiskPoint riskPoint, Integer shared, String pointName, String pointType, RiskEvaluationExcelMapBean mapBean) throws Exception {
        riskPoint.setName(pointName);
        riskPoint.setType(pointType);
        riskPoint.setId(mapBean.getPointCodeMap().get(riskPoint.getCode()).getId());
        Long riskDistrictId = null;
        if (riskPoint.getRiskDistrict() != null) {
            riskDistrictId = riskPoint.getRiskDistrict().getId();
        }
        if (shared == null || shared == 0) {
            riskPoint.setStatus(RiskPointStatus.AUDIT_SUCCESS.getIndex());
        }
        if (riskPoint.getSignInMethod() == null) {
            riskPoint.setSignInMethod(SignInMethodEnum.NOT_SIGN_IN.getCode());
        }
        riskPoint = riskPointService.update(riskPoint, riskDistrictId);
        //更新 mapBean
        Map<String, RiskPoint> pointCodeMap = mapBean.getPointCodeMap();
        pointCodeMap.put(riskPoint.getCode(), riskPoint);
        mapBean.setPointCodeMap(pointCodeMap);
        return riskPoint;
    }

    private void safeRemoveFromList(List<Integer> list, Integer index) {
        if (list.size() > 0) {
            list.remove(index);

        }
    }

    private boolean checkMeasureType(RiskEvaluationExcelMapBean mapBean, XSSFRow row, Integer measureTypeIndex, int inte,
                                     String sheetName, RiskMeasureType firstType, List<String> errorMessages) {
        boolean rt = true;
        Map<String, RiskMeasureType> measureTypesMap = mapBean.getMeasureTypesMap();
        //二级管控措施类型
        if (checkNullCell(row, measureTypeIndex + 2)) {
            if (!checkNullCell(row, measureTypeIndex + 3)) {
                errorMessages.add(sheetName + ":第" + (inte + 1) + "行, 管控措施二级类型不能为空");
                return false;
            }
        } else {
            String secondTypeName = getCellStringValue(row.getCell(measureTypeIndex + 2));
            if (StringUtils.isNotBlank(secondTypeName)) {
                if (isNum(secondTypeName)) {
                    secondTypeName = getNumberString(secondTypeName);
                }
                RiskMeasureType secondType = measureTypesMap.get("2_" + firstType.getId() + "_" + secondTypeName);
                // 二级不存在
                if (secondType == null) {
                    secondType = saveRiskMeasureType(secondTypeName, firstType.getId(), 2, measureTypesMap.size());
                    measureTypesMap.put("2_" + firstType.getId() + "_" + secondTypeName, secondType);
                    mapBean.setMeasureTypesMap(measureTypesMap);
                }
                //三级为空则直接返回二级
                if (checkNullCell(row, measureTypeIndex + 3)) {
                    mapBean.setMeasureTypeId(secondType.getId());
                    return true;
                }
                // 三级不空则验证三级
                String thirdTypeName = getCellStringValue(row.getCell(measureTypeIndex + 3));
                if (isNum(thirdTypeName)) {
                    thirdTypeName = getNumberString(thirdTypeName);
                }
                RiskMeasureType thirdType = measureTypesMap.get("3_" + secondType.getId() + "_" + thirdTypeName);
                if (thirdType == null) {
                    thirdType = saveRiskMeasureType(thirdTypeName, secondType.getId(), 3, measureTypesMap.size());
                    measureTypesMap.put("3_" + secondType.getId() + "_" + thirdTypeName, thirdType);
                    mapBean.setMeasureTypesMap(measureTypesMap);
                }
                // 三级正确
                mapBean.setMeasureTypeId(thirdType.getId());
                return true;
            }
        }
        return rt;
    }

    private RiskMeasureType saveRiskMeasureType(String typeName, Long parentId, Integer typeLevel, Integer sort) {
        RiskMeasureType type = new RiskMeasureType();
        type.setMeasureTypeName(typeName);
        type.setParentId(parentId);
        type.setTypeLevel(typeLevel);
        type.setSort(sort);
        riskMeasureTypeService.save(type);
        return type;
    }

    //判断单元格内容是否为空
    private boolean checkNullCell(XSSFRow row, Integer cellIndex) {
        XSSFCell cell = row.getCell(cellIndex);
        return cell == null || getCellValue(cell) == null || StringUtils.isEmpty(getCellStringValue(cell));

    }

    /**
     * 保存管控措施
     *
     * @param detailList
     * @param mapBean
     * @param content
     * @param controlLevelIds
     * @param responseUserIds
     * @param responseDepartIds
     * @param controlorState
     * @return
     */


    private List<RiskPointEvaluationDetailAddBean> builderDetailAddBean(List<RiskPointEvaluationDetailAddBean> detailList, RiskEvaluationExcelMapBean mapBean, String content, List<Long> controlLevelIds, List<Long> responseUserIds,
                                                                        List<Long> responseDepartIds, Integer controlorState, String hiddenDangerContent, Long accessSourceId, Long troubleshootingTypeId, String hiddenDangersDesc, String planRemark, Map<Long, List<BaseUser>> checkJobMap,
                                                                        String periodUnits, List<Integer> periodDaysList,List<String> periodWeekList,Date startTime,Date endTime, List<Long> investigateJobIds) {
        RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
        //类型:0分析方法选项,1评估方法选项,2数据字典
        detailAddBean.setMethodAnalyzeType(2);
        detailAddBean.setContentType(0);
        detailAddBean.setMethodId(mapBean.getMeasureTypeId());
        if (isNum(content)) {
            content = getNumberString(content);
        }
        detailAddBean.setContent(content);
        detailAddBean.setControlLevelIds(controlLevelIds);
        detailAddBean.setResponseUserIds(responseUserIds);
        detailAddBean.setResponseDepartIds(responseDepartIds);
        detailAddBean.setControlState(controlorState);
        if (hiddenDangerContent != null) {
            List<RiskHiddenDangerContent> hiddenDangerContentList = new ArrayList<>();
            RiskHiddenDangerContent hiddenContent = new RiskHiddenDangerContent();
            hiddenContent.setContent(hiddenDangerContent);
            if (accessSourceId == null) {
                //默认巡检排查
                accessSourceId = mapBean.getAccessSourceMap().get("巡检排查");
            }
            hiddenContent.setDateSource(accessSourceId);
            List<DangerContentExcelBean> userBeanList = builderDangerContentExcelBean(periodUnits, periodDaysList,periodWeekList,startTime,endTime, checkJobMap, null, hiddenDangersDesc, planRemark, troubleshootingTypeId);
            List<DangerContentExcelBean> jobBeanList = builderDangerContentExcelBean(periodUnits, periodDaysList,periodWeekList,startTime,endTime, null, investigateJobIds, hiddenDangersDesc, planRemark, troubleshootingTypeId);
            hiddenContent.setExcelUserBeanList(userBeanList);
            if (CollectionUtils.isEmpty(userBeanList)) {
                hiddenContent.setExcelJobBeanList(jobBeanList);
            } else {
                jobBeanList = new ArrayList<>();
                hiddenContent.setExcelJobBeanList(jobBeanList);
            }
            hiddenDangerContentList.add(hiddenContent);
            detailAddBean.setHiddenDangerContent(hiddenDangerContentList);
        }
        detailList.add(detailAddBean);
        return detailList;
    }


    /**
     * 保存管控措施
     *
     * @param detailList
     * @param mapBean
     * @param contents
     * @param controlLevelIds
     * @param responseUserIds
     * @param responseDepartIds
     * @param controlorState
     * @return
     */


    private List<RiskPointEvaluationDetailAddBean> builderDetailAddBean(List<RiskPointEvaluationDetailAddBean> detailList, RiskEvaluationExcelMapBean mapBean, List<String> contents, List<Long> controlLevelIds, List<Long> responseUserIds,
                                                                        List<Long> responseDepartIds, Integer controlorState) {
        if (!CollectionUtils.isEmpty(contents)) {
            for (String content : contents) {
                RiskPointEvaluationDetailAddBean detailAddBean = new RiskPointEvaluationDetailAddBean();
                //类型:0分析方法选项,1评估方法选项,2数据字典
                detailAddBean.setMethodAnalyzeType(2);
                detailAddBean.setContentType(0);
                detailAddBean.setMethodId(mapBean.getMeasureTypeId());
                detailAddBean.setContent(content);
                detailAddBean.setControlLevelIds(controlLevelIds);
                detailAddBean.setResponseUserIds(responseUserIds);
                detailAddBean.setResponseDepartIds(responseDepartIds);
                detailAddBean.setControlState(controlorState);
                detailList.add(detailAddBean);
            }
        }
        return detailList;
    }

    private List<DangerContentExcelBean> builderDangerContentExcelBean(String periodUnits, List<Integer> periodDaysList,List<String> periodWeekList,Date startTime,Date endTime, Map<Long, List<BaseUser>> checkJobMap, List<Long> investigateJobIds,
                                                                       String hiddenDangersDesc, String planRemark, Long troubleshootingType) {
        List<DangerContentExcelBean> list = new ArrayList<>();
        if ((!CollectionUtils.isEmpty(checkJobMap) || !CollectionUtils.isEmpty(investigateJobIds)) && StringUtils.isNotBlank(periodUnits) && (!CollectionUtils.isEmpty(periodDaysList) || !CollectionUtils.isEmpty(periodWeekList))) {
            DangerContentExcelBean bean = new DangerContentExcelBean();
            Integer flag = null;
            if (!CollectionUtils.isEmpty(checkJobMap)) {
                flag = 0;
            } else if (CollectionUtils.isEmpty(checkJobMap) && !CollectionUtils.isEmpty(investigateJobIds)) {
                flag = 1;
            }
            bean.setTroubleshootingType(troubleshootingType);
            bean.setFlag(flag);
            bean.setPeriodUnits(periodUnits);
            bean.setPeriodDaysList(periodDaysList);
            bean.setPeriodWeekList(periodWeekList);
            bean.setPlanStartTime(startTime);
            bean.setPlanEndTime(endTime);
            if (flag == 0) {
                List<InvestigateUserBean> userBeanList = new ArrayList<>();
                for (Map.Entry<Long, List<BaseUser>> entry : checkJobMap.entrySet()) {
                    InvestigateUserBean userBean = new InvestigateUserBean();
                    userBean.setJobId(entry.getKey());
                    List<BaseUser> value = entry.getValue();
                    List<Long> userIds = value.stream().map(BaseUser::getId).collect(toList());
                    userBean.setUserIds(userIds);
                    userBean.setHiddenDangersDesc(hiddenDangersDesc);
                    userBean.setRemark(planRemark);
                    userBeanList.add(userBean);
                }
                bean.setUserBeanList(userBeanList);
            } else if (flag == 1) {
                List<InvestigateJobBean> jobBeanList = new ArrayList<>();
                for (Long jobId : investigateJobIds) {
                    InvestigateJobBean jobBean = new InvestigateJobBean();
                    jobBean.setJobId(jobId);
                    jobBean.setHiddenDangersDesc(hiddenDangersDesc);
                    jobBean.setRemark(planRemark);
                    jobBeanList.add(jobBean);
                }
                bean.setJobBeanList(jobBeanList);
            }
            list.add(bean);
        }
        return list;
    }

    /**
     * map1(风险点,List<map2>)
     * map2(评估时间,List<map3>)
     * map3(序号,List<行数>)
     *
     * @param sheet
     * @param
     * @param itemIndex
     * @param evaluationTimeIndex
     * @return
     */
    //分组
    private RiskExcelErrorMessageBean convertDataMap(XSSFSheet sheet, Integer districtNameIndex, Integer pointNameIndex, Integer itemIndex, Integer evaluationTimeIndex, String sheetName, Integer shared, RiskEvaluationExcelMapBean mapBean, List<String> errorMessages) {
        RiskExcelErrorMessageBean bean = new RiskExcelErrorMessageBean();
        Map<String, List<Map<Date, List<Map<Integer, List<Integer>>>>>> dataGroupMap = new LinkedHashMap<>();
        XSSFRow row;
        for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
            row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            Long riskDistrictId = null;
            if (shared == null || shared == 0) {
                if (row.getCell(districtNameIndex) == null || getCellStringValue(row.getCell(districtNameIndex)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(districtNameIndex)))) {
                    errorMessages.add(sheetName + ":第" + (i + 1) + "行,区域名称不能为空");
                    continue;
                }
                String districtName = getCellStringValue(row.getCell(districtNameIndex));
                if (isNum(districtName)) {
                    districtName = getNumberString(districtName);
                }
                List<RiskDistrict> districtList = mapBean.getDistrictMap().get(districtName);
                if (!CollectionUtils.isEmpty(districtList)) {
                    riskDistrictId = districtList.get(0).getId();
                }
            }


            if (row.getCell(pointNameIndex) == null || getCellStringValue(row.getCell(pointNameIndex)) == null || StringUtils.isBlank(getCellStringValue(row.getCell(pointNameIndex)))) {
                errorMessages.add(sheetName + ":第" + (i + 1) + "行,风险单元名称不能为空");
                continue;
            }
            String pointName = getCellStringValue(row.getCell(pointNameIndex));
            if (isNum(pointName)) {
                pointName = getNumberString(pointName);
            }
            String key = riskDistrictId + "_" + shared + "_" + pointName;
            if (row.getCell(itemIndex) == null || getCellStringValue(row.getCell(itemIndex)) == null) {
                errorMessages.add(sheetName + ":第" + (i + 1) + "行,序号不能为空");
                continue;
            }
            Integer itemNumber = null;
            try {
                if (getCellValue(row.getCell(itemIndex)) instanceof Double) {
                    itemNumber = ((Double) getCellValue(row.getCell(itemIndex))).intValue();
                } else if (getCellValue(row.getCell(itemIndex)) instanceof String) {
                    itemNumber = Integer.valueOf((String) getCellValue(row.getCell(itemIndex)));
                }
            } catch (NumberFormatException e) {
                errorMessages.add(sheetName + ":第" + (i + 1) + "行,请填写数字类型的序号");
                continue;
            }
            if (row.getCell(evaluationTimeIndex) == null || getCellStringValue(row.getCell(evaluationTimeIndex)) == null) {
                errorMessages.add(sheetName + ":第" + (i + 1) + "行,评估日期不能为空");
                continue;
            }
            Date evaluationTime = null;
            try {
                Object date = row.getCell(evaluationTimeIndex).toString();
                if (date instanceof String) {
                    date = ((String) date).replace(".", "-").replaceAll("/", "-");
                    evaluationTime = SimpleDateFormatCache.getYmd().parse((String) date);
                }
            } catch (Exception e) {
                try {
                    evaluationTime = row.getCell(evaluationTimeIndex).getDateCellValue();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    errorMessages.add(sheetName + ":第" + (i + 1) + "行,评估日期(" + getCellStringValue(row.getCell(evaluationTimeIndex)) + ")填写错误,请填写正确的日期格式(如 2020-10-12)");
                    continue;
                }
            }
            List<Map<Date, List<Map<Integer, List<Integer>>>>> map2List = dataGroupMap.get(key);
            if (map2List == null) {
                map2List = new ArrayList<>();
                List<Integer> rowList = new ArrayList<>();
                rowList.add(i);
                Map<Integer, List<Integer>> map3 = new LinkedHashMap<>();
                map3.put(itemNumber, rowList);
                List<Map<Integer, List<Integer>>> map3List = new ArrayList<>();
                map3List.add(map3);
                Map<Date, List<Map<Integer, List<Integer>>>> map2 = new LinkedHashMap<>();
                map2.put(evaluationTime, map3List);
                map2List.add(map2);
                dataGroupMap.put(key, map2List);
            } else {
                for (Map<Date, List<Map<Integer, List<Integer>>>> map2 : map2List) {
                    List<Map<Integer, List<Integer>>> map3List = map2.get(evaluationTime);
                    if (map3List == null) {
                        map3List = new ArrayList<>();
                        List<Integer> rowList = new ArrayList<>();
                        rowList.add(i);
                        Map<Integer, List<Integer>> map3 = new LinkedHashMap<>();
                        map3.put(itemNumber, rowList);
                        map3List.add(map3);
                        map2.put(evaluationTime, map3List);
//                        map2List.add(map2);
                    } else {
                        for (Map<Integer, List<Integer>> map3 : map3List) {
                            List<Integer> integers = map3.get(itemNumber);
                            if (integers == null) {
                                integers = new ArrayList<>();
                                integers.add(i);
                                map3.put(itemNumber, integers);
//                                map3List.add(map3);
                            } else {
                                if (!integers.contains(i)) {
                                    integers.add(i);
                                }
                            }
                        }
                    }
                }
            }
        }
        bean.setDataGroupMap(dataGroupMap);
        bean.setErrorMessages(errorMessages);
        return bean;
    }

    @Override
    public Object getCellValue(XSSFCell cell) {
        return getCellValue(cell, false);
    }

    public String getCellStringValue(XSSFCell cell) {
        Object obj = getCellValue(cell, true);
        return obj == null ? null : obj.toString().trim();
    }

    private Object getCellValue(XSSFCell cell, boolean isText) {
        CellType cellType = cell.getCellType();
        DecimalFormat df = new DecimalFormat("0");


        Object value = null;
        switch (cellType) {
            case STRING: {
                value = cell.getStringCellValue();
                break;
            }
            case NUMERIC: {
                value = cell.getNumericCellValue();
                if (isText) {
                    BigDecimal decimal = new BigDecimal(value.toString());
                    int scale = decimal.scale();
                    if (scale < 1) {
                        //小于1代表科学计数或者整数
                        value = df.format(decimal);
                    } else {
                        value = String.valueOf(decimal);
                    }
                    return String.valueOf(value);
                }
                break;
            }
            case FORMULA: {
                value = cell.getNumericCellValue();
                if (isText) {
                    return value.toString();
                }
                break;
            }
        }
        return value;
    }

    @Override
    public Boolean isNum(String str) {
        try {
            new BigDecimal(str);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    private String getHour(String str){
        Pattern pattern = Pattern.compile("[^0-9]");
        Matcher matcher = pattern.matcher(str);
        return matcher.replaceAll("").trim();
    }

    private Boolean isWeek(String str) {
        return "周一".equals(str) || "周二".equals(str) || "周三".equals(str) || "周四".equals(str)
                || "周五".equals(str) || "周六".equals(str) || "周日".equals(str);
    }

    public Integer getWeekNum(String str) {
        Integer weekDayNum = null;
        switch (str) {
            case "周一":
                weekDayNum = 1;
                break;
            case "周二":
                weekDayNum = 2;
                break;
            case "周三":
                weekDayNum = 3;
                break;
            case "周四":
                weekDayNum = 4;
                break;
            case "周五":
                weekDayNum = 5;
                break;
            case "周六":
                weekDayNum = 6;
                break;
            case "周日":
                weekDayNum = 7;
                break;
            default:
        }
        return weekDayNum;
    }

    @Override
    public String getNumberString(String str) {
        if (str.equals("0.0")) {
            return "0";
        }
        if (str.startsWith("0") || str.length() > 512) {
            return str;
        }
        Double d = Double.valueOf(str);
        NumberFormat nf = NumberFormat.getInstance();
        String s = nf.format(d);
        if (s.indexOf(",") >= 0) {
            s = s.replace(",", "");
        }
        return s;
    }

    public static Integer getMonthNum(String month){
        switch (month) {
            case "一":
                return 1;
            case "二":
                return 2;
            case "三":
                return 3;
            case "四":
                return 4;
            case "五":
                return 5;
            case "六":
                return 6;
            case "七":
                return 7;
            case "八":
                return 8;
            case "九":
                return 9;
            case "十":
                return 10;
            case "十一":
                return 11;
            default:
                return 12;
        }
    }

}
